[Catalyst] Catalyst actions
Richard Jones
ra.jones at dpw.clara.co.uk
Thu May 17 16:38:41 GMT 2007
Help - I'm going round in circles with Catalyst actions. I want
http://localhost:3000/search to map to the method search() in
MyApp::Controller::Search, so I defined the method as:
sub search : Path Form('/search') { # a formbuilder method
if ( $form->submitted && $form->validate ) {
$c->detach('retrieve');
}
# etc;
}
sub retrieve : Private {
# performs db lookup, results in $rs, then:
if (! $rs->pager->total_entries || $rs->pager->total_entries > 1000) {
$c->stash->{error_msg} = sprintf 'Total records matched = %s, please
refine search', $rs->pager->total_entries;
$c->detach('search'); # re-load search form with message
}
else {
# display results in template
}
}
Now, if the $rs->pager->total_entries value triggers
$c->detach('search'), then the following error is generated:
Couldn't render template "file error - search/search: not found"
I also sometime see [% Catalyst.uri_for('search') %] translating to
'base_url/search/search' in the template, and though ugly, it does work.
It's probably got something to do with the definition of search() as an
empty Path, but that's the only way I could get the the address to read
http://localhost:3000/search as opposed to something ugly like
http://localhost:3000/search/search, as it does if I define search() as
a Local action, ie 'sub search : Local'.
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!
--
Richard Jones
More information about the Catalyst
mailing list