in reply to Catalyst: model & context object usage
I just finished the tutorial on CPAN a couple of weeks ago. A join is created shortly after your first code sample.
# Add a record to the join table for this book, mapping to # appropriate author $book->add_to_book_authors({author_id => $author_id}); # Note: Above is a shortcut for this: # $book->create_related('book_authors', {author_id => $author_ +id}); # Assign the Book object to the stash for display in the view $c->stash->{book} = $book;
As for your second question. You need to show me what you have in the list subroutine for me to understand what is going on. Your template file is calling 'books/list' which means 'sub list' in Books.pm (you should have created that in the previous tutorial "More Catalyst Basics' In the tutorial on CPAN it looks like this:
sub list : Local { # Retrieve the usual Perl OO '$self' for this object. $c is th +e Catalyst # 'Context' that's used to 'glue together' the various compone +nts # that make up the application my ($self, $c) = @_; # Retrieve all of the book records as book model objects and s +tore in the # stash where they can be accessed by the TT template $c->stash->{books} = [$c->model('DB::Books')->all]; # Set the TT template to use. You will almost always want to +do this # in your action methods (action methods respond to user input + in # your controllers). $c->stash->{template} = 'books/list.tt2'; }
If you haven't been there yet you can find all the most updated chapters on CPAN here
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Catalyst: model & context object usage
by marscld (Beadle) on Aug 11, 2008 at 05:46 UTC | |
by actualize (Monk) on Aug 11, 2008 at 06:49 UTC | |
by marscld (Beadle) on Aug 11, 2008 at 07:37 UTC | |
by actualize (Monk) on Aug 11, 2008 at 16:12 UTC | |
by marscld (Beadle) on Aug 12, 2008 at 01:30 UTC | |
|