想从url中删除action名称CakePHP [英] want to remove action name from url CakePHP
问题描述
我正在工作的Cakephp 2.x ..我想删除操作或控制器名称从url ...例如我面临的问题是这样
我在我的邮件控制器上有一个函数名 index ,其中显示所有手机号码
网址是
www.myweb.com/Messages
现在在我的控制器中,有一个名为 messages 的第二个函数,其中我收到了针对手机号码的邮件
现在我的网址在点击数字后变成
www.myweb.com/Messages / messages / 823214
现在我想删除操作名称消息,因为它看起来像... b $ b想拥有这样的网址
www.myweb.com/Messages/823214
当使用Route元素连接路由时,您可能希望传递参数。使用 Router :: connect()您可以定义哪些路由元素应该作为传递的参数提供:
// SomeController.php
public function messages($ phoneNumber = null){
//一些代码在这里...
}
// routes.php
路由器:: connect(
'/ messages /:id',// Eg / messages / number
array('controller'=>'messages','action'=>'messages'),
array(
// order matters因为这将只是映射:id
'id'=>'[0-9] +'
)
);
你也可以参考上面给出的链接,希望它能为你工作。 >
让我知道如果我可以帮助你更多。
i am working on a Cakephp 2.x.. i want to remove the action or controller name from url ... for example i am facing a problem is like that
i have a function name index on my Messages controller in which all the mobile numbers are displaying
the url is
www.myweb.com/Messages
now in my controller there is a second function whose name is messages in which i am getting the messages against the mobile number
so now my url becomes after clicking the number is
www.myweb.com/Messages/messages/823214
now i want to remove the action name messages because it looks weired... want to have a url like this
www.myweb.com/Messages/823214
When connecting routes using Route elements you may want to have routed elements be passed arguments instead. By using the 3rd argument of Router::connect() you can define which route elements should also be made available as passed arguments:
// SomeController.php
public function messages($phoneNumber = null) {
// some code here...
}
// routes.php
Router::connect(
'/messages/:id', // E.g. /messages/number
array('controller' => 'messages', 'action' => 'messages'),
array(
// order matters since this will simply map ":id"
'id' => '[0-9]+'
)
);
and you can also refer link above given by me, hope it will work for you.
let me know if i can help you more.
这篇关于想从url中删除action名称CakePHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!