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 when Using Any Parameters

Hi to all

I'm facing problems with route on phalcon

Here is my route:

$router->add('/carregador/carregar-por-quantidade/:param',
                 ['controller' => 'Carregador',
                  'action' => 'carregarPorQuantidade',
                  'param' => 1]);

Here is my notFound route:

 $router->notFound(
     [
         'controller' => 'Carregador',
         'action'     => 'route404',
     ]
 );

Here is my carregarPorQuantidadeAction on CarregadorController:

     public function carregarPorQuantidadeAction($quant) {
         var_dump($this->dispatcher->getParam("param"));
         var_dump($this->dispatcher->getParams());
         var_dump('oi teste');
         var_dump($quant);die;
    }

Here my route404Action:

 public function route404Action() {
         var_dump('naƵ encontrou a merda');
         var_dump($this->dispatcher->getParams());
     }

The problem is clear for me. When I try to use some parameter , it don't find the route to carregarPorQuantidade and goes to route404. If I dont use any parameters on carregarPorQuantidade, it finds the route perfectly. So, I'm new here and I need some help.

Thank you in advance.

Are you putting a trailing slash on the url?

This won't match your route: /carregador/carregar-por-quantidade/3/. If this is the problem, the router has a method that automatically strips trailing slashes.

I've also updated your post to use proper PHP syntax highlighting. Feel free to edit your post to see how I did that.

Thanks for your response.

No, there's no extra slash at the end.

When I use parameters on indexAction it works perferctly.

Are you putting a trailing slash on the url?

This won't match your route: /carregador/carregar-por-quantidade/3/. If this is the problem, the router has a method that automatically strips trailing slashes.

I've also updated your post to use proper PHP syntax highlighting. Feel free to edit your post to see how I did that.



125.7k
Accepted
answer

param in the route and array should be plural - params. I think the reason it's working without the params is because of the default router behaviour.

You are rigth. It was the plural of the parameter !!

thanks a lot.