Hi,
I send this email directly to Alessandro by mistake, so here it is for
all you people on this list:
alessandro cinelli wrote:
> hi,
> as written in the doc:
>
>
> 42.4.1.1 <http://42.4.1.1>. Action View Helper
>
> " The |Action| view helper enables view scripts to dispatch a given
> controller action; the result of the response object following the
> dispatch is then returned. These can be used when a particular
> action could generate re-usable content or "widget-ized" content."
>
> i'm curious to know why i have to do this in the View and not in the
> Controller.
> Would'nt be more logic to call the other action within the "caller"
> action and then assign the values to the View?
> is there a particular "design" reason or am i missing something?
I have not yet used it, but I understand it this way:
Imagine a forum engine, where there is a simple user profile box by
each post (a box with nickname and a photo, maybe).
You could write an action with gets user info from the model, and
prints it in this simple view. This box Is _reusable_, cause you can
put it by each post, or you could request it with ajax and show dhtml
popup in any place on your app.
If it was done directly in controller you would have had to write same
code twice - one to print the author profile in the action that shows
an post, and second time to return ajax popup with short profile, and
maybe one more action to print currently logged in user profile in the
right top corner of the page, so that user could see how other users
see him, etc...
What I want to say, is that you can have some parts of site which are
rendered in same way, and fetched in same way, but displayed in many
different controllers and actions. Putting the code in each action
would force you to write the same code at least in each action you use
it. And imagine you have to do a small change in that code...
Theoretically you could use a Partial insteed, but in that case you
need to fetch data manually in the action displaying your current script.
So If you have the data fetched in the current action anyway, use
partial helper, but if you need to include another model and write a
few lines of code to fetch some external data, better write a separate
action and use action helper.
Do I understand that correctly?
--
Regards
Szymon Wilkołazki