php - User Level Access in yii can't run well -



php - User Level Access in yii can't run well -

i newbie in yii, making website yii framework. first time in making user level access. i've created file ewebuser.php in protected/controllers/, code ` protected function loaduser(){ if ($this->_model === null){ $this->_model= user::model()->findbypk($this->id); } homecoming $this->_model; } function getlevel(){ $user = $this->loaduser(); if ($user) homecoming $user->status; homecoming ''; } }

then i've created function namely accessrules in admincontroller. code

public function accessrules() { homecoming array( array('allow', 'actions'=>array('index','delete','btnconf'), 'expression'=>'$user->getlevel()="supadmin"' ) ); } `

when type http://localhost/coretankuyii/index.php/admin/index in url while login user, admin or has not login can still access it. hope can access url has status=supadmin. can help me please?

change look "=="

public function accessrules() { homecoming array( array('allow', 'actions'=>array('index','delete','btnconf'), 'expression'=>'$user->getlevel()=="supadmin"' ) ); }

or if not work seek below

public function accessrules() { homecoming array( array('allow', 'actions'=>array('index','delete','btnconf'), 'expression'=>array('admincontroller','getlevel'); ) ); } public function getlevel(){ $user = $this->loaduser(); if($user->status=='supadmin') homecoming true; else homecoming false; }

php yii

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -