generating URL from a named route

I am working with an example from Phalcon docs but have some problems.

The URL component should build /manual/en/translate.adapter.html but instead the following URL is being build: /manual/en/translate.adapter\.html (slash before .html).

My router is a copy from the docs:

// matches "/manual/en/translate.adapter.html"
$router->add(
    "/manual/([a-z]{2})/([a-z\.]+)\.html",
    array(
        "controller" => "manual",
        "action"     => "show",
        "language"   => 1,
        "file"       => 2
    )
)->setName("theexample"); // I have only added this line

The above code is from http://docs.phalconphp.com/en/latest/reference/routing.html#usage-examples

Then, when I want to generate an URL like here:

$url = $this->url->get(array(
  "for" => "theexample",
  "language" => "en",
  "file" => "translate.adapter",
));

var_dum($url);

I receive this:

string '/manual/en/translate.adapter\.html' (length=34)

The same problem is with $this->response->redirect().

What is wrong? I have copied the example from the docs and only named a route. How to fix this slash before a dot?

TIA



84.0k

There's no way to "fix" the slash before the dot, Phalcon\Router uses regular expressions to add flexibility to routes, without the slash the dot is not escaped and preg_match will handle it as a wildcard for any characters. http://php.net/manual/en/regexp.reference.dot.php



17.1k

Thanks for your reply!

The problem is that generated route doesn't match the base route, so it cannot be used to produce valid URLs or redirections.

Do you know how to workaroud it in some pretty way?