We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

route: notFound, setting params error

i Have in my route conf:

    $router->notFound(array(
    'module' => 'public',
    'controller' => 'error',
    'action' => 'index',
    'params' => '404'
));

in controller:

    public function indexAction($error = NULL) {
    var_dump($error);
    die();
    }

the response is: string(2) "04", i need 404 param

but if change the route to:

      $router->notFound(array(
    'module' => 'public',
    'controller' => 'error',
    'action' => 'index',
    'params' => '0404'
    ));

the response is: string(2) "404" , and it oks for me!..

and i need that 404 param... why is this problem??, bug in notFound?



1.6k
Accepted
answer

I've found the problem. The params variable usually looks like "/param1/param2/param3/param4" ("/:params" translates to "(/.)"). As such, the router "trims" the params content using substr(params, 1) to remove the first character which is usually a forward slash. See here.

I've changed it so that it trims only forward slashes: https://github.com/phalcon/cphalcon/pull/10277

The good news is, it looks like 2.0.1 will be arriving in the next few days so you won't have to wait long for it to come to a stable release.

Sounds good!, thanks!!