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.

Routing issue for same pattern url

Hi everybody,

I want to create 2 routes below:

  • For main cate: /{cate:[a-z]{2}} (only have 2 characters from a-z)
  • For sub cate: /{sub_cate:[a-z0-9-]+}-{cate:[a-z]{2}} (normal sub cate slug and end with main cate slug)

But it's not work. Can you give me some solutions?

Route source:

$router->add( "/{cate:[a-z]{2}}", "Category::cate" );

$router->add( "/{sub_cate:[a-z0-9-]+}-{cate:[a-z]{2}}/", "Category::sub" );

Sample:

  • example.com/xd
  • example.com/funny-story-2017-xd

The order of declaration matters, Phalcon router traverses the registered patterns from BOTTOM TO TOP!

Try reordering your add statements:

$router->add( "/{sub_cate:[a-z0-9-]+}-{cate:[a-z]{2}}/", "Category::sub" );
$router->add( "/{cate:[a-z]{2}}", "Category::cate" );


205

I got no luck. Maybe have to process on action in controller!



107.5k
Accepted
answer
edited Jan '17

In your sample:

example.com/funny-story-2017-xd

But in code here:

/{sub_cate:[a-z0-9-]+}-{cate:[a-z]{2}}/

with slash at the end. Try without slash at the end.



205

Thank you, it's ok when remove slash at the end of route define

In your sample:

example.com/funny-story-2017-xd

But in code here:

/{sub_cate:[a-z0-9-]+}-{cate:[a-z]{2}}/

with slash at the end. Try without slash at the end.