Restricting and redirecting other user from admin in cakePHP -


i'm getting issue after logging in site. there 2 kinds of users i.e. 'admin','employer'. when i've logged in employer, can access restricted area of admin. below appcontroller of site..

class appcontroller extends controller {         public $helpers = array('form', 'html', 'js', 'time', 'auth');          // change template extension .php instead of .ctp         var $ext = '.php';         public $components = array(             'session',             'auth' => array(                 'loginaction' => array(                     'controller' => 'users',                     'action' => 'login'                 ),                 'loginredirect' => array('controller' => 'users', 'action' => 'index'),                 'logoutredirect' => array('controller' => 'users', 'action' => 'login'),                 'authenticate' => array('form' => array('fields' => array('username' => 'email'))),                 'authorize' => array('controller')             )         );          public function isauthorized($user) {              // admin can access every action             if (isset($user['type']) && $user['type'] === 'admin') {                 return true;             }              // default deny             return false;         }          public function beforefilter() {             $this->auth->allow(array('view', 'index','assessment','question'));         }      } 

now here controller has methods admin.

class topicscontroller extends appcontroller {      public $scaffold = 'admin';     public function beforefilter() {          if($this->auth->user('type')!='employer'){            parent::beforefilter();            $this->auth->allow(array('view', 'index','moveup'));         } else {            $this->auth->deny(array('view', 'index','moveup'));            $this->redirect(array('controller' => 'employer' , 'action' => 'index'));         }      }     public function isauthorized($user) {         return true;     }      public function index() {       $this->set('topics', $this->topic->children());     }  } 

if admin url www.example.com/admin/topics , employer redirected www.example.com/admin/employer not right url redirected.

also want know public $scaffold = 'admin'; it's little unclear me. please me..

ok.. found 1 way redirect, made issue solved now.. still looking proper answer if has..

i changed code from

$this->redirect(array('controller' => 'employer' , 'action' => 'index')); 

to

$this->redirect('employer'); 

.. edit: alex, i've used

$this->redirect(array('controller' => 'employer' , 'action' => 'index', 'admin'=>false)); 

and it's working too..


Comments