[Catalyst] putting an object in the stash

Will Hawes wdhawes at gmail.com
Tue Mar 13 10:46:45 GMT 2007


On 13/03/07, Octavian Rasnita <orasnita at gmail.com> wrote:
> Hi,
>
> 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).
>
> 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 %]?
>
> And by the way, which do you think is the recommended way?

I'd have thought the second one. $obj is essentially just a hash, so
I'm not sure what you'd stand to gain using the first method.



More information about the Catalyst mailing list