If I want to gather some data from the database and use it in multiple actions of a controller, how would I do this?
Şu anda sadece modeli erişmek ve (evet, ben hepinize soruyorum neden bu kadar ... bu verimsiz olduğunu biliyorum!) Her eylem ayrı ayrı veri almak:
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);
}
Ben Zend Framework bu yapmıyor olsaydı ben sadece yapıcı koymak ve daha sonra herhangi bir nesne yöntemi $this->whatever ile gitmek için iyi olabilir ama ben (ZF bu nasıl görmüyorum istiyorum Ben belki sadece aptal bir kodlama hatası yapılmış ve aslında bunu yapmak için doğru bir yer mi?) ... init bunu yapışmasını çalıştı () ama işe yaramadı.
* EDIT: Ben varsa, diyelim ki, 7 denetleyicisi eylemler ve ben (init veritabanını vurur kodu koymak) yöntemi daha sonra ben denir her eylem ile veritabanı vuracaktır. Yeterli değil.