Rewriting url using routes in cakephp

2019-08-30 06:47发布

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...

标签: cakephp-2.3
1条回答
爷、活的狠高调
2楼-- · 2019-08-30 07:38

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');
     ...
}
查看更多
登录 后发表回答