我有两个基本相同的操作,但需要不同的 URL。通常我会用它_forward()
来渲染其他动作:
class MyController extends Zend_Controller_Action
{
public function actionOneAction()
{
$this->_forward('action-two');
}
public function actionTwoAction()
{
$this->view->foobar = 'foobar';
}
}
但是,我有一些代码正在发生preDispatch()
,我只想执行一次:
class MyController extends Zend_Controller_Action
{
public function preDispatch()
{
//execute this only once before actionOne or actionTwo, but not both
}
public function actionOneAction()
{
$this->_forward('action-two'); //this won't work because preDispatch() will get called a second time
}
public function actionTwoAction()
{
$this->view->foobar = 'foobar';
}
}
所以我想也许我可以简单地直接调用该函数,如下所示:
class MyController extends Zend_Controller_Action
{
public function preDispatch()
{
//execute this only once before actionOne or actionTwo, but not both
}
public function actionOneAction()
{
$this->actionTwoAction(); //execute the same code as actionTwoAction()
}
public function actionTwoAction()
{
$this->view->foobar = 'foobar';
}
}
但是现在 Zend Framework 抱怨找不到action-one.phtml
视图脚本。我不想渲染 actionOne 的视图脚本。我想渲染 actionTwo 的视图脚本。我需要做什么?