[Catalyst] How to pass args/data from one controller to another?
corey at 31415926535.com
Sat Sep 29 07:39:37 GMT 2007
Dustin Suchter wrote:
> So I've thought of a few different ways to pass data between Local
> methods across two different controllers, but none of them seem like
> good ideas. I still don't fully get the Catalyst framework yet, so
> I'm asking a very open question, "What are a few right ways to do
> this?" TIMTOWTDI, of course.
> Controller "Library" has a function "list_books" that, duh, displays
> a list of books in the lib. Each book is clickable creating an
> action in another function in Libarary called "read_book" that's
> only job in life as a function is to pass the $book_id over to the
> default action in the "ReadABook" controller. How do you pass the
> $book_id? Through the stash, though a path arg using 'uri_for' and a
> redirect, using forward?
I'm a newbie with Catalyst as well, so hopefully if I say anything too
incorrect, others will chime in. I think the best way to handle the
book_id is simply to pass it via the URL. So in your read_book
controller, you'd have something like:
my ($self, $c, $book_id) = @_;
See the following page in the tutorial for passing arguments via the URL:
Hope that helps.
More information about the Catalyst