Rewriting url using routes in cakephp

北慕城南 提交于 2020-01-25 22:22:37

问题


I am trying to create a custom route in cakephp.I need the url in the following format

http://domain.com/mygroup?id=23

I am trying like the following

 Router::connect('/:sluggroup?id=:id', 
 array('controller' => 'groups', 
 'action' => 'postdetail'),array('pass' =>  array('sluggroup','id')));

How can i achieve this?

Thanks...


回答1:


Try using the route:

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.

In your Controller's use:

public function postdetails() {
     $group = $this->passedArgs[0];
     $id = $this->request->query('id');
     ...
}


来源:https://stackoverflow.com/questions/22953163/rewriting-url-using-routes-in-cakephp

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