I'm working on cakephp project. I have problem but don't know how to resolve it. I have variable store in Session call is 'roles'. And I have some routes are manage by this roles but denied with other roles. So how can I config routes by roles like this. Give me a tips. Thank you so much
Sample maybe I want like this
if($this->Session->read("role")=="admin"){
allow("/admin/dashboard");
}else{
denied("/admin/dashboard");
}
if($this->Session->read("role")=="staff"){
allow("/staff/dashboard");
}
Ello, mate.
Are you using the Auth component to authenticate logins? if you're using it, you can allow and deny controller actions with:
//AdminController
$this->Auth->allow('dashboard'); //Allow the dashboard method on admin controller
$this->Auth->deny('dashboard'); //Deny the dashboard method on admin controller
You can also make conditions on beforeFilter() to redirect it based on the role:
//ExampleController
public function beforeFilter()
{
if($this->Session->read("role")=="admin")
{
return $this->redirect(array('controller' => 'yo_controller', 'action' => 'yo_action'));
}
//.......
}
If you want, have a look on the cookbook about authorization, it may help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.