啊是经过 2011-08-09 16:13:51 3023次浏览 0条回复 0 0 0

在controller.php文件里加下面代码,就可以强制跳转login界面

public function beforeAction($action)
{
  if(parent::beforeAction($action))
  {
    $route ='site'.'/'.$action->id;  //site是控制器
    if(!$this->allowIp(Yii::app()->request->userHostAddress) && $route!=='site/error')
      throw  new CHttpException(403,"You are not allowed to access this page.");		  
    $publicPages = array(
      'site/login',
      'site/error',
    );
    if($this->password!==false && Yii::app()->user->isGuest && !in_array($route, $publicPages))
      Yii::app()->user->loginRequired();
    else 
      return true;
    }
}
	
protected function allowIp($ip)
{
  if(empty($this->ipFilters))
    return true;
  foreach($this->ipFilters as $filter)
  {
    if($filter==='*' || $filter===$ip || (($pos=strpos($filter,'*'))!==false && !strncmp($ip,$filter,$pos)))
      return true;
    }
    return false;
}
亿速云
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册