[Catalyst] Relationship layout

Will Smith willbelair at yahoo.com
Wed Oct 5 20:00:55 CEST 2005


Thanks for the tip. Everything works well now for the has_a. 
In the muic::M::CDBI::Artist I define the has_many as (artist has many Cd):
-------
music:M:::CDBI::Artist->has_many(cds => 'music::M::CDBI::Cd'=>'artistid');
-------
I've tried all possibilities but just can't get the data out of the stash.
In muic::C::CDBI::Artist i have a sub named beatle
-----
sub beatle : Local {
    my ( $self, $c ) = @_;
    
    $c->stash->{artist} = music::M::CDBI::Artist->search_like(name=>'%beatle%');
    $c->stash->{template} = 'Artist/test.tt';
}
--------
If I run the script: ---------
print $artist->name,"\n";

foreach ($artist->cds) {
        print "\t",$_->title,"\n";
}---------------
it worksin the STDOUT. 
1-how can I get it on the Template.
2-on a template (within catalyst), can we set the EVAL_PERL => 1 in order to use rawperl by:
[% SET EVAL_PERL  = 1 %]
[% PERL %]
#!/perl/usr/perl
....
[% END %]
 
 
Thanks a lot.

Andreas Marienborg <omega at palle.net> wrote:
You seem to mix models and controllers.. Models are where teh 
relationships go (as you obviously have gotten to work, thats good). 
Controllers use theese models to fetch the right stuff from the DB/ 
backend, and make it available to the View(s). The way to do that is 
via the "stash":

package music::C::Cd; # note the lack of CDBI here, the CDBI is 
naming convention for Models, but rarely used in controller namespaces.

sub blue : Local {
my ($self, $c) = @_;
$c->stash->{cds} = music::M::CDBI::Cd->search(title => "Blue");
$c->stash->{template} = 'cds/list.tt'; # For instance
}


then you can access cds from your template

[% WHILE (cd = cds.next) %]

[% cd.title %]
[% END %]

or somesuch.

I would recomend the article by our beloved Jesse
http://www.perl.com/pub/a/2005/06/02/catalyst.html

and also the documentation of the Catalystpackage itself:
http://cpansearch.perl.org/~mramberg/Catalyst-5.33/

hope that helps you a little bit along

andreas



		
---------------------------------
Yahoo! for Good
 Click here to donate to the Hurricane Katrina relief effort. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20051005/e27ced83/attachment.htm


More information about the Catalyst mailing list