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.

Phalcon two single routes

I have a problem. I have two routes:

$router->add('/news/{alias:[a-z\-]+}(/?)', array(
      'module' => 'frontend',
      'controller' => 'news',
      'action' => 'view',
      'news_id' => 1,
      'lang' => 'md',
))->setName('news_view_short_e'); //=> /news/282334-alias-news

AND route => /news/index/:

$router->add('/{lang:[' . $langsDefined . ']{2}+}/{controller:[a-z]{3,50}+}(/?)', array(
     'module' => 'frontend',
     'controller' => 2,
     'action' => 'index',
     'lang' => 1,
))->setName('default_module_lang');

When I use these routes. site.com/news/index not working. But if I remove route with alias. Route site.com/news/index working good. How I can resolve conflict?



126.6k
Accepted
answer
edited Dec '17

Obviously this second one overrides the first one, i guess you need to add them in reversed order you are adding them now.

edited Dec '17

What does your $langsDefined variable look like?

{lang:[' . $langsDefined . ']{2}+} this should limit the match to two characters, so news shouldnt be matched

Oh yea that's true.