Search code examples
phpcase-sensitivelithium

Is there a possibility for not case sensitive Routes in li3?


I would like to create a Route at Lithium, which matches

  • /abc
  • /abC
  • /aBc
  • and so on

So far i have something like this:

Router::connect('/abc', array('Example::test'));

Is there a possibility to change it to something uncase sensitive.

Thanks for your help, i couldn't find a thing in the docs.


Solution

  • You should be able to do it like this:

    Router::connect('/{:dummy:[aA][bB][cC]}', array('Example::test'));
    

    Edit: There is a nicer way to do it as well by creating the Route object by your self

    Router::connect(new Route(array(
            'pattern' => '@^/ab?$@i',
            'params' => array('controller' => 'example', 'action' => 'test'),
            'options' => array('compile' => false, 'wrap' => false)
    )));
    

    If i brake out the pattern above '@^/ab?$@i'

    • @ == start of regex
    • ^ == start of line
    • /ab == look for "/ab
    • ? == optional trailing slash
    • $ == end of line
    • @ == end of regex
    • i == make it case insensitive

    And you can find more information here: http://li3.me/docs/lithium/net/http/Route