0
votes

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.

1

1 Answers

1
votes

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');
        }
}