Action and pass variable to all actions in symfony 1.4

后端 未结 2 1973
后悔当初
后悔当初 2021-01-26 18:43

I want to make some action (php script) before all actions in my frontend app and then pass a result from that script to actions in variable - so I can get variable value from a

2条回答
  •  庸人自扰
    2021-01-26 18:59

    If the filter solution dont feet your needs, you can also create a base action class with a preExecute function:

    // app/frontend/lib/baseActions.class.php
    
    class baseActions extends sfActions
    {
       public function preExecute()
       {
          $this->myVar = .... // define your vars...
       }
    }
    

    Then your module actions class extends your baseActions class:

    // 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
          ... 
       }
    }
    

    if you have to use the preExecute function in your module class action, remember to call parent::preExecute() in it.

提交回复
热议问题