您好我正在使用yii框架,我已经在Layout / main.php中编写了如下代码
array('label'=>'Dashboard', 'url'=>array('/site/todays_task'),'visible'=>$user-checkAccess('Team Leader,employee')),
并在我的Protected / component / WebUser.php代码中如下
public function checkAccess($operation, $params=array())
{
if (empty($this->id))
{
// Not identified => no rights
return false;
}
$role = $this->getState("Role");
if ($role === 'admin') {
return true; // admin role has access to everything
}
if (strstr($operation,$role) !== false) { // Check if multiple roles are available
return true;
}
// allow access if the operation request is the current user's role
return ($operation === $role);
}
}
因此管理员可以看到仪表板链接,也因为管理员可以访问webuser checkaccess方法中的所有内容,我想隐藏该仪表板链接到管理员
答案 0 :(得分:0)
编写第二个函数来执行此操作,为admin部分返回false;
public function checkAccessNoAdmin($operation, $params=array())
{
if (empty($this->id))
{
// Not identified => no rights
return false;
}
$role = $this->getState("Role");
if ($role === 'admin') {
return false; // admin role has no access here
}
if (strstr($operation,$role) !== false) { // Check if multiple roles are available
return true;
}
// allow access if the operation request is the current user's role
return ($operation === $role);
}
}
然后打电话给那个:
array('label'=>'Dashboard', 'url'=>array('/site/todays_task'),'visible'=>$user-checkAccessNoAmdin('Team Leader,employee'))