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

i18n routing

Maybe I am not searching in the right place. But how can I add UTF-8 characters to the routing with regular expresion ? In a normal preg_match i would do something like:

preg_match('/calin/u', $string); // this will match calin or călin

I couldn't find a way to append the /u condition to the routing. Any feedback on this would be appreciated. Thanks

$router->addGet('/cauta[/]{0,1}$', array( // this should also match caută
    'module' => 'frontend',
    'controller' => 'post',
    'action' => 'search',
    'activePage' => 'search',
    'activeCategory' => 'search',
));


98.9k

Try this:

$router->addGet('#/cauta[/]{0,1}$#/u', array( // this should also match caută
    'module' => 'frontend',
    'controller' => 'post',
    'action' => 'search',
    'activePage' => 'search',
    'activeCategory' => 'search',
));


51.2k

Nope. Not working. it is not matching the route with your example. I have tried something similar with

$router->addGet('#^/('.$categories.')/([a-zA-Z0-9\-]+)[/]{0,1}$#/u') 

But it failed.



98.9k
Accepted
answer
edited Oct '14

Ok, it works this way:

<?php

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

$router->add('#^/caut[aă][/]{0,1}$#u', array( // this should also match caută
    'module' => 'frontend',
    'controller' => 'post',
    'action' => 'search',
    'activePage' => 'search',
    'activeCategory' => 'search',
));

$router->handle('/cauta');
var_dump($router->wasMatched());

$router->handle('/caută');
var_dump($router->wasMatched())

Note that #u modifier does not perform transliteration of characters, it just changes the way the pattern and subjects are handled expecting five and six octet UTF-8 character sequences.