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.

multiple routes pattern problem

Hi I've got problem with multiple route patterns, to handle different routes by one controller action.

        http://www.blabla.com/search/aa/blabla/

        http://www.blabla.com/search/aa/blabla/?from=2015-11-12&to=2015-11-16

        http://www.blabla.com/search/aa/blabla.php?from=2015-11-12&to=2015-11-16

        http://www.blabla.com/search/aa/blabla/2015-11-12/2015-11-16/

        http://www.blabla.com/search/aa/blabla/from/2015-11-12/to/2015-11-16/

my routing

                    $router->add('/search/{a:[a-zA-Z]{2}}/{b:[a-zA-Z0-9_-]+}/:params',
                        array(
                            "controller" => "search",
                            "action"     => "index",
                            'params' => 3
                        )
                    );

                    $router->add('/search/{a:[a-zA-Z]{2}}/{b:[a-zA-Z0-9_-]+}/{from:/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/}/{to:/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/}/:params',
                        array(
                            "controller" => "search",
                            "action"     => "index",
                            'params' => 5
                        )
                    );

when I run http://www.blabla.com/search/aa/blabla/ it gives me Action aa was not found on handler search

$this->dispatcher->getParam("from"); not working either



5.1k
Accepted
answer
edited Sep '15

Not sure but i tested your code and it didn't work until i moved it at the end of routing list. So i guess it has something to do with what the documentation on routing states: https://docs.phalconphp.com/pl/latest/reference/routing.html :

Internally, all defined routes are traversed in reverse order until Phalcon\Mvc\Router finds the one that matches the given URI and processes it, while ignoring the rest.

The bold highliting for the "reverse" word is mine of course.



3.5k

for my second problem $this->dispatcher->getParam("from"); it seems there is a problem on my regexpression, and i dont know why

        /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/
        2015-01-01
        2015-12-31

anyhow i changed it to simple one