私はフロントエンドアプリケーションのすべてのアクションの前にいくつかのアクション(PHPスクリプト)を作成し、そのスクリプトの結果を変数のアクションに渡したいと思います。すべてのアクション。私はどこでこれを宣言すべきですか?symfony 1.4のすべてのアクションにアクションとパスを渡す
0
A
答えて
2
どのような情報ですか?
filtersをお勧めします。あなたのapps/frontend/config/filters.yml
で
:
<?php
class myCustomFilter extends sfFilter
{
public function execute ($filterChain)
{
if ($this->isFirstCall())
{
// do what ever you want here.
$config = Doctrine_Core::getTable('Config')->findAll();
sfConfig::set('my_config', $config);
}
$filterChain->execute();
}
}
そして、すべての場所、あなたのデータを取得することができます:
rendering: ~
myfilter:
class: myCustomFilter
ファイルlib/filter/myCustomFilter.php
作成
sfConfig::get('my_config');
3
をフィルタソリューションの場合あなたのニーズを満たさない場合は、preExを使ってベースアクションクラスを作成することもできますecute機能:
// app/frontend/lib/baseActions.class.php
class baseActions extends sfActions
{
public function preExecute()
{
$this->myVar = .... // define your vars...
}
}
その後、あなたのモジュールのアクションクラスは、あなたのbaseActionsクラスを拡張:
// app/frontend/modules/myModule/actions/actions.class.php
class myModuleActions extends baseActions
{
public function executeIndex(sfWebRequest $request)
{
// var $this->myVar is available in any action and in your template
...
}
}
あなたのモジュールクラスアクションでpreExecute機能を使用する必要がある場合は、それにparent::preExecute()
を呼び出すことを忘れないでください。