Custom Role management in cakephp


Posted on 10 Oct 15 by Vickey

By using ACL we can manage roles in cakephp but if you dont know how it will be implement you can use a simple custom code.



$controller= strtoupper($this->params['controller']);
$action =strtoupper($this->params['action']);

if( isset($permissions['default_permissions'][$controller][$action]) && !in_array($this->Auth->user('role_id'),$permissions['default_permissions'][$controller][$action]))
return $this->redirect('/');

In this code USER is controller name and 'ADD' and 'EDIT' are actions. Here I have two types of users one is admin role id 1 and other is front end user role id is 2. So here admin can use 'ADD',  'EDIT', and 'index' page but normal use can use only 'INDEX'. Action that not given in 'permissions' array can access every one 

If this post help you reduce time to develop, you can help me to maintain this website :)