class CAdminAccessControlFilter extends CAccessControlFilter
{
protected function preFilter($filterChain)
{
$app=Yii::app();
$request=$app->getRequest();
$user = Yii::app()->controller->module->getComponent('adminUser');
$verb=$request->getRequestType();
$ip=$request->getUserHostAddress();
foreach($this->getRules() as $rule)
{
if(($allow=$rule->isUserAllowed($user,$filterChain->controller,$filterChain->action,$ip,$verb))>0) // allowed
break;
else if($allow<0) // denied
{
$this->accessDenied($user);
return false;
}
}
return true;
}
}
再重写CController类的filterAccessController方法
Php代码
复制代码 代码如下:
public function filterAccessControl($filterChain)
{
$filter = new CAdminAccessControlFilter();
$filter->setRules($this->accessRules());
$filter->filter($filterChain);
}
//在这里我们使用自定义的filter类替换了原来的filter
OK,到这里我们就可以在此Controller的accessRules()中指定adminUser的授权了
您可能感兴趣的文章: