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

Routing problem

There is two routes:

    $router->add('/places/:action/:params', array(
        'controller' => 'places',
        'action'     => 1,
        'params'     => 2
    ));

    $router->add('/places/add/:params', array(
        'controller' => 'places',
        'action'     => 'add',
        'params'     => 1
    ));

And second one don't works. Why? It's just an intersection, and priority should be given to the second one, because it's more specific.

What you mean don't works ?

edited Apr '16

What you mean don't works ?

Query /places/add/ provided by first router, but it must be provided by second (it's my opinion)

edited Apr '16

But how you know what it's querying ? Those routes are the same thing to be honest.

You have the same router. There are just two routes which are same thing:

    $router->add('/places/:action/:params', array(
        'controller' => 'places',
        'action'     => 1,
        'params'     => 2
    ));

If you access here add it will execute action called add from controller places, this:

    $router->add('/places/add/:params', array(
        'controller' => 'places',
        'action'     => 'add',
        'params'     => 1
    ));

will do the same.

How i can gifure out which route is executing this action ?

But how you know what it's querying ? Those routes are the same thing to be honest.

You have the same router. There are just two routes which are same thing:

   $router->add('/places/:action/:params', array(
       'controller' => 'places',
       'action'     => 1,
       'params'     => 2
   ));

If you access here add it will execute action called add from controller places, this:

   $router->add('/places/add/:params', array(
       'controller' => 'places',
       'action'     => 'add',
       'params'     => 1
   ));

will do the same.

How i can gifure out which route is executing this action ?

I solved the problem. More general rules need to be declared before the narrower. In this case, first processed narrow rules, then the general rules. This allows you to bypass the execution of the general rule, giving a chance to execute narrow rules. So like that:

BAD: ... var $a = 1;

if (($a == 1) || ($a == 2)) { return 'Hahahahaha!'; } if ($a == 1) { return 'I do not give executed:((('; } ...

TRUE: ... var $a = 1;

if ($a == 1) { return 'I gave execute!!!!'; } if (($a == 1) || ($a == 2)) { return 'Support the narrow rules together!!!'; } ...

edited Apr '16

But in this case there is no difference as i wrote above.

    $router->add('/places/add/:params', array(
        'controller' => 'places',
        'action'     => 'add',
        'params'     => 1
    ));

This route is executing action add from controller places

    $router->add('/places/:action/:params', array(
        'controller' => 'places',
        'action'     => 1,
        'params'     => 2
    ));

If you will just have this the result will be the same action add will be executed from controller places

You can test if your current order of routes is working by changing controller in /places/add/:params' to some not exisiting controller. It should throw exception.