Cakephp路由(在PHP中) [英] Cakephp routing (in PHP too)

查看:322
本文介绍了Cakephp路由(在PHP中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Cake,但是如何使路由像:

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

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

不区分大小写?

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

MY_URL.com/hellouser工作正常,但不是MY_URL.com/HelloUser无法正确路由。

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

我试过/ heelouser / i但仍然没有。

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

推荐答案

文档中所示,您可以使用正则表达式以限制匹配路由元素。您正在寻找的正则表达式代码段是:

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



路线定义



将文档和您的特定正则表达式放在一起,将以不区分大小写的方式匹配url / hellouser

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

第三个参数用于限制路径元素的可能值 - 在本例中为hellouser以不区分大小写的方式。

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

这篇关于Cakephp路由(在PHP中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆