Cakephp routing (in PHP too) [closed]

限于喜欢 提交于 2020-01-07 09:38:50

问题


I am using Cake, but how do I make the routing like:

Router::connect('/', array('controller' => 'homes', 'action' => 'index'));

case insensitve?

For instance:

Router::connect
(
    '/:user', 
    array('controller' => 'teachers', 'action' => 'contentProfile', 1),
    array('user' => 'hellouser')
);

MY_URL.com/hellouser works fine but not MY_URL.com/HelloUser does NOT route correctly.

And I have tried /heelouser/i and still nothing.


回答1:


As indicated in the docs, you can use regular expressions to restrict matching route elements. The regex snippet you are looking for is:

'(?i:hellouser)' 

Route definition

Putting the docs and your specific regex together, here's a route that will match the url /hellouser in a case insensitive manner:

Router::connect(
    '/:user', 
    array('controller' => 'teachers', 'action' => 'contentProfile', 1),
    array('user' => '(?i:hellouser)')
);

The third argument is used to restrict the possible values of route elements - in this case to "hellouser" in a case insensitive manner.



来源:https://stackoverflow.com/questions/12526099/cakephp-routing-in-php-too

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!