[Catalyst] Catalyst actions

Matt S Trout dbix-class at trout.me.uk
Fri May 18 13:18:56 GMT 2007


On Fri, May 18, 2007 at 09:33:29AM +0100, Richard Jones wrote:
> >>I also sometime see [% Catalyst.uri_for('search') %] translating to
> >>'base_url/search/search' in the template, and though ugly, it does work.
> >
> >That's cuz it generates a URI relative to the current namespace. I'd 
> >generally
> >avoid passing strings to uri_for except for static files, and instead pass
> >$controller->action_for($name_of_action_method).
> 
> But it's in the template I'm using uri_for, and action_for doesn't seem 
> to work there ie [% Catalyst.action_for('search') %]

Not really surprising given action_for is a CONTROLLER method and 'Catalyst'
is your MyApp CONTEXT OBJECT. Try Catalyst.controller.action_for('search') :)
 
> >>I've also tried playing with calling the default method 'index' and
> >>'default', and various attributes Local, Path, Global (I know that one's
> >>wrong) but ran into problems with all of those. I can't do a
> >>$c->res->redirect to the url '/search' as I need the original search
> >>params reloading. Can anyone see an obvious solution to this? Probably
> >>to do it the correct way!
> >
> >$c->uri_for($self->action_for('search'), $c->req->query_parameters); ?
> 
> That also gets the form re-displayed, but without the query_params and 
> without the 'Submit' button, which is generated in the template as part 
> of the form object ie [% form.submit %]. Any further thoughts? Thanks 
> for your help so far btw :-)

Is your form method="POST" ? In that case the form data will be in
body_parameters - you could always just do $c->req->params, I prefer to
have my code wired up fairly explicitly for GET vs. POST but that's more
an obsession with the HTTP and URI standards than any practical concern.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/             http://www.shadowcatsystems.co.uk/ 



More information about the Catalyst mailing list