Zend Framework - Use data collected from database in multiple actions

WrZz

New Member
If I want to gather some data from the database and use it in multiple actions of a controller, how would I do this?Currently I just access the model and retrieve the data separately in each action (yes, I know this is inefficient... it's why I'm asking you all!):\[code\]public function indexAction(){ $model = $this->_getStuffModel(); $this->view->results = $model->fetchEntries();}public function anotherAction(){ $model = $this->_getStuffModel(); $foo = $model->fetchEntries(); foreach($foo as $k => $v) { //manipulate the data } $this->_helper->json($theoutput);}\[/code\]If I were not doing this in Zend Framework I would just put it in the constructor and then be good to go with \[code\]$this->whatever\[/code\] in any method of the object but I don't see how to do this in ZF (I tried sticking it in init() but it didn't work... maybe I just made a stupid coding error and that is actually the correct place to do this?).*EDIT: If I have, say, 7 actions in a controller and I put the code that hits the database in the init() method then I will hit the database with each and every action that is called. That won't do.
 
Back
Top