> -- Ed Lazor <edlazor@internetarchitects.biz> wrote
> (on Tuesday, 27 January 2009, 10:41 AM -0800):
>> Which is better?
>>
>> Option #1
>> Using the action method to collect data and pass (push?) it to the
>> view through variables
>>
>> Option #2
>> Using action view helpers within views to retrieve (pull?) data for
>> display
>>
>> I've always read that the controller is supposed to prepare
>> everything
>> for the view. Option #2 seems like a cleaner approach though, so I'm
>> wondering what you think.
>
> Option #2 is a lot of overhead, and terrible from a performance
> standpoint.
>
> The point of the Controller in the first place is to manage the
> environment, and determine what models and views need to be
> instantiated. Typically you will push results of queries to your model
> into your view, or simply push your model into the view; the view then
> determines what to display, and how to display it. When seen from this
> view point, using the action() view helper seems like an indirection
> --
> it's treating actions as if they were models.
>
> So, short answer, use Option #1.
The main work of the current controller should be done in the
controller's action method (option #1). Any other data that you need
in the view (e.g. sidebar with latest comments) can be collected
directly within the view using a view helper that talks to the
relevant model. Whatever you do, don't use the action() view helper :)
Regards,
Rob...
没有评论:
发表评论