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\Mvc\Router get pattern based on a matched route

Hello community, I hit the wall with this one.

I need to get matched pattern by a name of the defined route.

Router groups are defined as:

        $loginRoutes = new RouterGroup(['controller' => 'exampleController']);
        $loginRoutes->add('/loginPage',['action' => 'login'])->setName('login');

So I want to resolve it by a named route (login in this case):

    $routeName = 'login';
    $resolveRoute = $this->_router->getRouteByName($routeName);
        var_dump($resolveRoute);    //returns proper route as object

        var_dump($this->_router->getParams());
        var_dump($this->_router->getControllerName());
        var_dump($this->_router->getActionName());
        var_dump($this->_router->getMatchedRoute());

The problem is, getRouteByName returns object with all properties defined as protected. I can see the pattern, but I cannot re-use it. Is there a way to fetch pattern from router component? I'm too tired at this point, I must be missing something.

This is the dump of it:

object(Phalcon\Mvc\Router\Route)#78 (10) {
  ["_pattern":protected]=>
  string(10) "/realURL"
  ["_compiledPattern":protected]=>
  string(10) "/realURL"
  ["_paths":protected]=>
  array(2) {
    ["controller"]=>
    string(14) "exampleController"
    ["action"]=>
    string(5) "login"
  }
  }


46.5k
Accepted
answer
edited Jan '16

Well, thanks Rubber duck debugging :) https://en.wikipedia.org/wiki/Rubber%5duck%5debugging

    var_dump($resolveRoute->getPattern()); //string "/loginPage"