[Catalyst] putting an object in the stash

Simon Wilcox simonw at digitalcraftsmen.net
Tue Mar 13 11:09:39 GMT 2007


On Tue, 13 Mar 2007, Octavian Rasnita wrote:

> I have a DBIC record object like
> my $obj = $c->model("Database::Table")->find($id);
>
> The table has very many fields and I would like to put their values in a TT
> template without inserting them one by one in the stash.
>
> So I would like to create a hash ref from $obj where the name of the field
> is the key and the value from the table is the value in that hash, then use
> $c->stash($hashref).

I'm not sure why you would want to do this ?

> Is it possible to create that hash (ref) from $obj, or I need to do
> something like
>
> $c->stash->{obj} = $obj;
>
> and in the template use [% obj.name1 %]... [% obj.name2 %]?

I just put the object in the stash. TT abstracts the method/hash key
accessor issue for you so that [% obj.name1 %] will work whether obj is an
object with a name1 accessor or a hash with a name1 key.

Simon Wilcox

-- 
Digital Craftsmen Ltd
Exmouth House, 3 Pine Street, London. EC1R 0JH
t 020 7183 1410 f 020 7099 5140 m 07951 758698
w http://www.digitalcraftsmen.net/



More information about the Catalyst mailing list