SirEdward wrote: > > A view helper is able to access the model so long as it is only reading > from the model. Most MVC diagrams will show this. As long as the view > helper is only retrieving data from the model and not writing to it then > this is fine. > > So this makes perfect sense in my opinion to use a view helper for > widgets. For example, you may have a widget that shows the top 10 search > results on a page, the view helper is making a request for this data from > the model but not writing data to it. So in my modules/views directory I > have a helpers directory which contains several view helpers which extend > Zend_View_Helper_Abstract. These classes also generates the HTML to > display on screen so both the logic and rendering as you put it are in the > one class. >
Yes, the view helper should only read from model and not write to it. So I guess that approach would do. Its just that i don't want to store both the logic & the view in one class - but that is not a problem since using a helper we might be able to render any particular view for that widget. The only thing i am worried about is the case when you need a widget with some AJAX functionality. It should definitely have a receiving backend for data processing. How are you handling this kind of cases? lightflowmark wrote: > > Hi - I'm interested in this as I'm not happy with my current method for > handling widgets. > How would your widget helper be different to the action() view helper? > Cheers, > Mark > Well as you may know the ActionStack or action() view helper is a quite clear approach in terms of coding BUT it hits application performance pretty much because it creates a whole dispatch loop for each of your actions. This is not a way to go especially if you have a lot of widgets in your layouts. There's a good article on the topic: "Why the Zend Framework Actionstack is Evil" (http://www.rmauger.co.uk/2009/03/why-the-zend-framework-actionstack-is-evil/) and also a proposal for removing action() view helper in ZF 2.0. (http://framework.zend.com/issues/browse/ZF-5840) The widget view helper on the other hand is called in the same dispatch process, calls a model to pull data out of it and then passes it all to it's view (or just renderes itself, like in SirEdward's example above). Dmitry. -- View this message in context: http://www.nabble.com/Widgets-and-why-do-I-need-a-custom-view-helper.-tp23747369p23758904.html Sent from the Zend Framework mailing list archive at Nabble.com.