[Catalyst] generic db table list

Aran Deltac aran at arandeltac.com
Fri Jun 2 04:39:27 CEST 2006


On 6/1/06, Fernan Aguero <fernan at iib.unsam.edu.ar> wrote:
> 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>

Instead of this:

> [% FOREACH column in row %]
> <td>[% column.value %]</td>
> [% END %]

Do this:

[% FOREACH column IN row.result_source.columns %]
<td>[% row.get_column(column) %]</td>
[% END %]

This is assuming your are using DBIC.

> </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) )

Go to the docs for template toolkit and search for the string "The
FOREACH directive can also be used to iterate through the entries in a
hash array.".

Aran

> 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
>
>
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>



More information about the Catalyst mailing list