[Catalyst] How to pass args/data from one controller to another?

Antano Solar solar345 at gmail.com
Sun Sep 30 03:10:45 GMT 2007


> That's what I was trying before, but check this out:
>
> # CODE 1
> #in MyApp::Controller::Libaray
> sub read_book : Local {
>     my ($self, $c) = @_;
>     $c->response->redirect($c->uri_for('/readabook/read_book' ));
> }
>
> # CODE 2
> #in MyApp::Controller::Libaray
> sub read_book : Local {
>     my ($self, $c) = @_;
>     my ($bid, $pid) = ("2","345");
> $c->response->redirect($c->uri_for("/readabook/read_book/$bid/$pid"));
> }
>
> # CODE 3
> #in MyApp::Controller::ReadABook
> sub read_book : Local {
>     my ($self, $c, $book_id, $page_id) = @_;
>     #do stuff...
> }
>
> When I use CODE 1 the app correctly executes CODE 3, but of course
> there are no args passed along, so $book_id and $page_id are
> uninitalized. When I use CODE 2, Catalyst executes my default action
> (home) - my guess it it does this because it can't find a specific
> "/readabook/read_book/2/345". For the record I also tried using CODE
> 1 and stuffing the values I needed into the stash, but that didn't
> work either.
>
> So how do you pass args with uri_for? I was hoping to RTFM, but I
> couldn't find the FM for "uri_for", and I decided to consult the
> Oracle (this mailing list) before trouncing through Catalyst sourcecode.
>
> -d
>

The only manual for anything that you might come across when using Catalyst  
is the POD documentation itself and should be searched on search.cpan.org
http://search.cpan.org/~jrockway/Catalyst-Manual-5.701002/lib/Catalyst/Manual/Cookbook.pod


The values are passed as different arguments to uri_for.
You could do $c->uri_for('readabook/read_book','$bid','$pid') .
you can check the value returned by  using $c->debug->log..

Antano Solar John









More information about the Catalyst mailing list