问题
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