0

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

4

1 に答える 1

0

これを行う 2 つ目の関数を作成し、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'))
于 2012-12-25T07:34:03.950 に答える