使用cakephp中的路由重写URL [英] Rewriting url using routes in cakephp
本文介绍了使用cakephp中的路由重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在cakephp中创建自定义路由。我需要以下格式的网址
I am trying to create a custom route in cakephp.I need the url in the following format
http://domain.com/mygroup?id=23
我正在尝试以下操作
Router::connect('/:sluggroup?id=:id',
array('controller' => 'groups',
'action' => 'postdetail'),array('pass' => array('sluggroup','id')));
我该如何实现?
谢谢...
推荐答案
尝试使用以下路线:
Router::connect('/:group/*', array('controller'=>'groups','action'=>'postdetail'),
array(
'pass' => array('group')
)
);
这将路由所有内容,因此,如果您有其他控制器,则在使用之前需要特定的路由
This will route everything, so if you have other controllers, you will need specific routes for them BEFORE the one above.
在您的控制器中使用:
public function postdetails() {
$group = $this->passedArgs[0];
$id = $this->request->query('id');
...
}
这篇关于使用cakephp中的路由重写URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文