[Catalyst] Catalyst::Model::CDBI::CRUD observation

Andy Grundman andy at hybridized.org
Fri Apr 29 20:37:09 CEST 2005


Will Hawes wrote:
> With regard to the handling of CDBI objects in the above module. The process() method (line 124) stashes the class for the current request and, if an id is present in the URL, does a retrieve and stashes the returned item. But if no id is present, no CDBI objects are created.
> 
> In Hops, the objects are actually created in the "list" template, which does class->retrieve_all and builds a HTML table. So the data is being retrieved in the View part of the app?!
> 
> It's late on Friday and maybe I'm missing something here, but surely CRUD.pm should be following Maypole's example and stashing an array(ref) of CDBI objects to pass to the template instead.

Are you talking about doing this?

$c->stash->{list} = [ Model->retrieve_all ];

in template:
[% FOR item IN list %]
   <tr><td>[% item.field1 %]</td><td>[% item.field2 %]</td>....
[% END %]

As far as I know this is the standard way of using CDBI objects in TT. 
It's technically "retrieved" in the view, but it's sure better than the 
HTML::Template-style way of doing it where you had to create your own 
giant arrayref/hashref structure to pass to the template.

-Andy



More information about the Catalyst mailing list