Search code examples
perlcatalyst

How can I forward a public path to another Catalyst controller?


Let say the public URL /faq is linked to the private path /faq/index in my Catalyst application:

package MyApp::Controller:FAQ;
sub index :Path {
[....]

How can I do a forward to /faq from another controller, that is how can I know that the action for the URL /faq is /faq/index ? Something like:

$c->forward(c->dispatcher->get_action_by_path( "/faq" )); # does not work

Solution

  • I got the answer for the Catalyst mailing list:

    my $path = "/" . join '/', @{$c->req->args};
    
    $c->request->path($path);
    $c->dispatcher->prepare_action($c);
    
    $c->detach($c->action, $c->req->args);