问题描述
我想在前端应用程序中的所有操作之前执行一些操作(php 脚本),然后将该脚本的结果传递给变量中的操作 - 这样我就可以从所有操作中获取变量值.我应该在哪里声明这样的东西?
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 all actions. Where should I declare sth like this?
推荐答案
如果过滤器解决方案不能满足您的需求,您还可以创建一个带有 preExecute 函数的基本操作类:
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...
}
}
然后你的模块操作类扩展你的 baseActions 类:
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
...
}
}
如果你必须在你的模块类操作中使用 preExecute 函数,记得在其中调用 parent::preExecute()
.
if you have to use the preExecute function in your module class action, remember to call parent::preExecute()
in it.
这篇关于动作并将变量传递给 symfony 1.4 中的所有动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!