Php 动作并将变量传递给symfony 1.4中的所有动作

Php 动作并将变量传递给symfony 1.4中的所有动作,php,symfony1,Php,Symfony1,我想在我的前端应用程序中的所有动作之前做一些动作(php脚本),然后将该脚本的结果传递给变量中的动作——这样我就可以从所有动作中获得变量值。我应该在哪里申报这样的东西?什么样的信息 我建议你使用 在您的应用程序/frontend/config/filters.yml中: rendering: ~ myfilter: class: myCustomFilter 创建文件lib/filter/myCustomFilter.php: <?php class myCustomFilter e

我想在我的前端应用程序中的所有动作之前做一些动作(php脚本),然后将该脚本的结果传递给变量中的动作——这样我就可以从所有动作中获得变量值。我应该在哪里申报这样的东西?

什么样的信息

我建议你使用

在您的
应用程序/frontend/config/filters.yml
中:

rendering: ~
myfilter:
  class: myCustomFilter
创建文件
lib/filter/myCustomFilter.php

<?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();
  }
}

什么样的信息

我建议你使用

在您的
应用程序/frontend/config/filters.yml
中:

rendering: ~
myfilter:
  class: myCustomFilter
创建文件
lib/filter/myCustomFilter.php

<?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();
  }
}

如果过滤器解决方案不能满足您的需要,您还可以创建一个带有预执行函数的基本操作类:

// 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()

如果筛选器解决方案不符合您的需要,您还可以使用preExecute函数创建基本操作类:

// 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()