may be duplicate but I don\'t get any proper answer or help
actually I want to do like:
my current URL is : http://mysite.com/MyController/view/page1
Try the following code for your controller, Here am using GroupsController as an example
You add this in your app\Config\routes.php
Router::connect('/groups/:slugParam', array('controller' => 'groups', 'action' => 'index'), array('slugParam' => '[a-zA-Z0-9]+'));
This should redirect all requests of the form
http://www.site.com/groups/* to http://www.site.com/groups/index
( * => whatever comes after the controller name )
So now i have to alter my default index function in GroupsController to reflect this change
request->params); this where all data is intercepted...
if(isset($this->request->params['slugParam']) && !empty($this->request->params['slugParam'])) {
// i have a slug field in groups databsae and hence instead of id am using slug field to identify the post.
$data = $this->Group->findBySlug($this->request->params['slugParam']);
$this->set('group', $data);
$this->render('/groups/view');
}
}
}
?>