We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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 https://docs.phalcon.io/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



98.9k

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. https://php.net/manual/en/regexp.reference.dot.php



26.3k

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?