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.


dmitrybelyakov wrote:
> 
> 
> 
> Recently i did a lot of reading trying to discover a best way to implement
> widgets in my layouts.
> 
> As being quite new to ZF i found several ways to do this (action stack.
> action view helper, view->partial() helper etc), but first let's run
> through requirements for such functionality.
> 
> The widget should probably consist of two files: 
> 
> 1) an actual logic of the widget (what model to pull data from, what
> method to call, what parameters to pass to model)
> 
> 2) the actual view file of that widget
> 
> It's clear that the first file should act as a controller. But it should
> not be an ActionController because we don't really what a whole dispatch
> loop (action view helper OR action stack) as it hits perfomance pretty
> much
> 
> The widget file should be distributed along with a corresponding module,
> that it pull's data from. In fct it may have a collection of such widgets
> for it's services.
> 
> The widget should return rendered content and should be easyly executed in
> controller plugin or action controller.
> 
> 
> The most clear and fast in terms of perfomance thing i discovered was
> inflecting
> rendered widgets into my response object in postDispatch hook.
> 
> This is very cool and we can also use View Helpers such as partial() view
> helper.
> 
> But my question is - where should we put the logic for pulling data out of
> model ???
> 
> My idea is to write a special view helper that may be called like this:
> 
> $view->widget->('widgetName', 'moduleName');
> 
> It will then call execute the widget file from the module's folder, do
> it's logic, render a view & return content.
> 
> Sounds pretty simple, but before i do this i just wonder am i missing
> something? May be what i want to do may be achieved some other way?
> 
> Thanks for your opinion on the topic :)
> 
> Dmitry.
> 

-- 
View this message in context: 
http://www.nabble.com/Widgets-and-why-do-I-need-a-custom-view-helper.-tp23747369p23751488.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to