Well, I think it depends on the situation. If you really need a list of bugs on most pages, and you're not going to use that list in any other place than the view helper, I'd just go ahead and do the model instantiation in the view helper. On the other hand, if you need a list of active bugs available throughout your system and you're going to use them in your view helper among other places, you probably want to write an Action Helper that instantiates the Bugs model and queries it, and then passes the query results to the view (in preDispatch), and then have the view helper grab that data from the view.
CM <http://cmorrell.com/> *Chris Morrell* Web: http://cmorrell.com Twitter: @inxilpro <http://twitter.com/inxilpro> On Wed, Mar 31, 2010 at 10:23 AM, eduardocury <[email protected]> wrote: > > Hello Chris thanks for your reply. > > Since the beginning i have used in this way > > // View helper > class My_View_Helper_BugList extends Zend_View_Helper_Abstract > { > public function bugList(array $bugs) > { > foreach ($bugs as $bug) { > $bug = (array) $bug; > // ... > } > } > } > > > But after really realize the use of object-oriented programming and > the datamapper patterns, now any collection of data is not a simple > array of data but really instances of my models. So i moved to your > first example. > > class My_View_Helper_BugList extends Zend_View_Helper_Abstract > { > public function bugList(Bug $model) > { > // ... > } > } > > But now im in a situation that i need repeat my code in a dozen of > differente places . So if im not include the model or a service > directly into the helper i really need to have my instances in any > controller action to properly pass the data to view. > > > So i think will keep in this way as i always have done (instantiating > the stuff in controller) , at least this give me a peace of mind for > not breaking any rule. > > Thank you > > > -- > View this message in context: > http://n4.nabble.com/model-attached-in-a-view-helper-tp1746059p1746836.html > Sent from the Zend Framework mailing list archive at Nabble.com. > >
