Yii Framework Forum

Why the checkaccess() returned false?


(George_lu) #1

Hi guys! I am using rbac of yii1.1 to manage my roles. I want to only allow the user who have ‘readIssue’ can access the “actionView”, my controller is as below:

public function actionView($id)
{
		
	$model=$this->loadModel($id);
	
	if(!Yii::app()->user->checkAccess('readIssue',array('issue'=>$model)))
	{
		throw new CHttpException(403,'You are not authorized to per-form this action');
	}
	
	$this->render('view',array(
		'model'=>$this->loadModel($id),
	));
}

But, the ‘checkAccess()’ returned false so the user who have ‘readIssue’ permission can‘t access the ‘actionView’, could you tell me why?

I tried to var_dump( Yii::app()->user); and I got:

E:\projects\yiiroot\trackstar\protected\controllers\IssueController.php:75: object ( CWebUser )[ 19 ] public ‘allowAutoLogin’ => boolean true public ‘guestName’ => string ‘Guest’ (length=5) public ‘loginUrl’ => array (size=1) 0 => string ‘/site/login’ (length=11) public ‘identityCookie’ => null public ‘autoRenewCookie’ => boolean false private ‘_keyPrefix’ => string ‘a0a10d1b4832b7caf267662eda15b419’ (length=32) private ‘_access’ => array (size=0) empty public ‘behaviors’ => array (size=0) empty private ‘_initialized’ (CApplicationComponent) => boolean true private ‘_e’ (CComponent) => null private ‘_m’ (CComponent) => null


(George_lu) #2

I got it.

public function actionView($id)
{
$model=$this->loadModel($id);

	$project=$this->loadProject($model->project_id);
	
	$params=array('project'=>$project);
	/* var_dump(Yii::app()->user->checkAccess('readIssue',$params));exit; */
	if(Yii::app()->user->checkAccess('readIssue',$params))
	{
	$this->render('view',array(
		'model'=>$this->loadModel($id),
	));}
	else
	{
	throw new CHttpException(403,'You are not authorized to per-form this action');
	}
}