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.

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',
));


83.4k

Try this:

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


32.7k

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.



83.4k
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.