MVC (Re: DBIx::Class - Related Tables)

Raphael Mankin raph at mankin.org.uk
Tue Oct 7 13:33:02 BST 2008


On Tue, 2008-10-07 at 12:50 +0100, Andy Wardley wrote:
> Raphael Mankin wrote:
> > The problem here is not with the ORM but rather that you are breaking
> > the MVC separation and putting controller logic in the view. A good ORM
> > would have its data cached so that your test might not require two SQL
> > queries. However, the template is, in this instance, the wrong place to
> > put the test.
> 
> I disagree.  In fact, I think you may have fallen into the MVC Silver
> Bullet[*] trap.
> 
> There are many different kinds of logic in a web, including application
> (business) logic, web framework logic (e.g. routing requests and responses to
> and from handlers), access logic (authorisation and authentication), data
> logic (both internal ORM mapping and external entity modeling) and
> presentation (view) logic.
> 
> Each has its own place, and the place for presentation logic is in templates.
> 
>     [% # display custom panel based on user status
>        IF user.is_admin;
>           INCLUDE admin/controls;
>        ELSIF user.is_logged_in;
>           INCLUDE user/greeting;
>        ELSE;
>           INCLUDE user/login;
>        END;
>     %]
> 
> It is not up to the framework, the application, the controller or the ORM
> to decide how this information should be presented to the user.  This is
> the domain of the web designer / information architect / usability consultant
> and the templates are their playground.

If there were many such IF statements in my templates I would tend to
use separate templates for the user states (or whatever) and let the
controller route to the appropriate one. However, choking the cat with
cream is not the only way to kill it. 

IIRC Struts will route on the return code from the controller; just
return the user state as your return code and you get the right thing.



More information about the london.pm mailing list