0

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.

Andresch Serj
  • 35,217
  • 15
  • 59
  • 101

1 Answers1

1

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');
        }
}
hungneox
  • 9,333
  • 12
  • 49
  • 66
  • Wait, so i can use the methods that i would define in the plugin in the controller as well? How did i not know that? I actually never saw anyone doing this. Thanks for pointing it out to me! Have a nice day! – Andresch Serj Dec 20 '11 at 10:04
  • Like i said. Yes. Thank you. Actually already tried it and works fine ... Didn't know i had a brother though. But the more the marier right? ;-D – Andresch Serj Dec 20 '11 at 10:13
  • 1
    @AndreschSerj haha you're so funny :) – hungneox Dec 20 '11 at 10:19