这就是我想要做的事情:
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
//some code
$this->view->var = 'something';
}
public function differentAction()
{
//here, I want to execute the indexAction, but render the differentAction view script
}
}
如何从其他操作执行代码,但渲染当前视图脚本?我希望视图变量应用于differentAction视图脚本。
答案 0 :(得分:4)
显然它就像调用$this->indexAction()
一样简单。 = /
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
//some code
$this->view->var = 'something';
}
public function differentAction()
{
$this->indexAction(); //still renders the differentAction() view script.
}
}
答案 1 :(得分:1)
您也可以考虑制作私有/受保护的方法:
class IndexController extends Zend_Controller_Action
{
private function _sharedCode
{
$this->view->var = 'something';
}
public function indexAction()
{
$this->_sharedCode();
}
public function differentAction()
{
$this->_sharedCode();
}
}