开发者

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

开发者 https://www.devze.com 2022-12-13 15:35 出处:网络
This is what I want to do: class IndexController extends Zend_Controller_Action { public function indexAction()

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

精彩评论

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

关注公众号