开发者

Zend Framework: How to execute the code from a different action?

This is what I want to do:

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

How can I execute the code from a different action, but render the current view script? I want the view variable to apply to the differentAction view sc开发者_开发技巧ript.


Apparently it's as easy as calling $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.
    }
}


You might also consider making a private / protected method:

class IndexController extends Zend_Controller_Action
{
    private function _sharedCode
    {
        $this->view->var = 'something';
    }

    public function indexAction()
    {
        $this->_sharedCode();
    }

    public function differentAction()
    {
        $this->_sharedCode();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜