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

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?



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