[Catalyst] DBI search method problems

Andreas Marienborg omega at palle.net
Mon Feb 27 23:49:53 CET 2006


On 27. feb. 2006, at 23.26, David Rio Deiros wrote:

>
> In lib/dbtest/Controller/Contest.pm I add:
>
>     sub test : Local {
>         my ( $self, $c, $id ) = @_;
>         $c->stash->{item} = dbtest::Model::CDBI::Contest->search(id  
> => 2);
>         #$c->stash->{item} = dbtest::Model::CDBI::Contest->retrieve 
> (2);
>         $c->stash->{template} = 'Contest/test.tt';
>     }
>
> And this is the view's code:
>
> [% item.id %]
>
> Also, I have tried an standalone application (outside the catalyst
> framework) and this code works:
>
>     foreach my $c ( testdbdrio::Contest->search(id => 2) ) {
>         print $c->id, $c->name . "\n";
>     }
>
> What am I missing?
>

you are missing the foreach from your example.

$c->stash->{item} = dbtest::Model::CDBI::Contest->search(id => 2);

will populate your item in the stash as either an array or an  
Class::DBI::Iterator (not sure which one at this hour).


andreas





More information about the Catalyst mailing list