[Catalyst] generic db table list

Fernan Aguero fernan at iib.unsam.edu.ar
Fri Jun 2 01:12:23 CEST 2006


Or ... learning TT along the way.

What I want to do: have a generic 'list' action that lists
the contents of a database table. I'm planning to use this
with more complex queries (not just one table per page) but
right now I'm starting with functionality similar to that
provided by InstantCRUD to learn along the way. 

Basically I want to end up with an action and an associated
view that for any resultset, will do something like

<table>
[% FOREACH row in rs.next() %]
<tr>
[% FOREACH column in row %]
<td>[% column.value %]</td>
[% END %]
</tr>
[% END %]
</table>

Right now, for one particular table, I'm doing this:
[% FOREACH row in rs.next() %]
<tr>
<td>[% row.user_id %]</td>
<td>[% row.username %]</td>
...
...

and it works, but this is just because I'm using the column
names for this particular case ... or saying it another way,
I've not found a way for looping through all the keys of a
hash in TT, like you can do with raw perl: 
foreach $key ( keys(%hash) )

All the examples in the Template Toolkit pods always use the
exact names of the keys for accessing values ... and I find
it difficult to follow the InstantCRUD example as the 'list'
action (InstantCRUD.pm, line 211) does not define any
'columns' in the stash, but they are used in the associated
'list.tt' template (where does this array come from?)

For those familiar with InstantCRUD, there are some column
names begin pushed into the stash in another action (auto)
... but I cannot see how they're connected.

Thanks in advance for any help, suggestion or clarification,

Fernan





More information about the Catalyst mailing list