The \Phalcon\Url can not reverse url with route name

$objDi->set('router', function() use ($arrConfig){

    $_objRouter = new \Phalcon\Mvc\Router(false);

    $_objRouter->add("/:controller/:action.html", array('controller' => 1, 'action' => 2))->setName('test');

    $_objRouter->notFound(array('controller' => 'error', 'action' => 'notfound'));

    return $_objRouter;

}, true);

I define an route with name "test" :

$_objRouter->add("/:controller/:action.html", array('controller' => 1, 'action' => 2))->setName('test');

used for example xxx.com/index/index.html

but i use the \Phalcon\Url::get method with "test" route in IndexController::indexAction, the result is not right.

$_strLinker = $this->url->get(array('for' => 'test', 'controller' => 'item', 'action' => 'view'));
die($_strLinker);

The result is not "/item/view.html", but is "/item/view.ht".

how to do?

Try escaping the dot with a backslash.

$_objRouter->add("/:controller/:action\.html", array('controller' => 1, 'action' => 2))->setName('test');

SInce it's a regular expression, the dot means match all, so perhaps it not playing nice.



741
edited Feb '16

Try escaping the dot with a backslash.

$_objRouter->add("/:controller/:action.html", array('controller' => 1, 'action' => 2))->setName('test');

SInce it's a regular expression, the dot means match all, so perhaps it not playing nice.

yes,the right route is yours, the dot with a backslash. but the \Phalcon\Url::get() method reverse url string maybe not right.

$_strLinker = $this->url->get(array('for' => 'test', 'controller' => 'item', 'action' => 'view'));
die($_strLinker);

the result is /item/view\.ht