こんにちは、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 メソッドのすべてにアクセスできるため、そのダッシュボードのリンクを管理者に非表示にしたいと考えています。