i am writing a web application and i need all the data returned/computed in all actions of one specific controller to return data to the layout (not the view).

So after each action, a controller variable needs to be passed to the layout so the layout can use it.

In detail, i want to store the calculated data in jSon in the head.

Any ideas anyone of how to do this? I thought about a controller plugin but i have no idea of how to access the desired parameters then and i really don't want to use a singleton for all this.

有帮助吗?

解决方案

Let use, this method is executed before every action

public function preDispatch() {
}

for example

public function preDispatch()
{
        //calculate something
        //this is an example
        if($this->getRequest()->getActionName()=="admin")
        {
            $this->_helper->layout->setLayout('admin');
        }
        else
        {
            $this->_helper->layout->setLayout('user');
        }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top