Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



90.1k
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.