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 regex problem

I'm trying to match something like:

Both should work.

This is my route:

$router->add("/{board:[a-zA-Z_]+}/{page:[0-9]?}", [ 'controller' => 'board', 'action' => 'show'] )->setName('show-board');

This however requires the trailing slash even without the page specified. Is there a way to need the slash ONLY with the page?

$router->add("/{board:[a-zA-Z_]+}/?{page:[0-9]*}", [ 'controller' => 'board', 'action' => 'show'] )->setName('show-board');

You probably need one or more numbers for the page param, so i replaced the question mark (zero or one occurrence) with the asterisk (zero or multiple occurrences)

edited Mar '14

Hey. That works for the routing part. However $url->get(); builds incorrect links with that route. ( ). Is there something I could do to make to $url->get(); to not put that question mark to the URL?

This is the function that builds the wrong link:

{{ url.get(['for': 'show-board', 'board': title, 'page': page.before]) }}

You could add two routes:

$router->add("/{board:[a-zA-Z_]+}", [ 'controller' => 'board', 'action' => 'show'] )->setName('show-board');
$router->add("/{board:[a-zA-Z_]+}/{page:[0-9]+}", [ 'controller' => 'board', 'action' => 'show'] )->setName('show-board-pagination');


Yep, that's what I've been doing, was just wondering if there was a better/shorter way. Thanks. :P