首页 > 代码库 > Yii 动作过滤的方法

Yii 动作过滤的方法

 

 

 

 

 1     protected function _init() 2     { 3          4     } 5      6     public function beforeAction($action) 7     { 8         //黑名单 9         $blackList = array(‘test‘,‘login‘,‘registe‘,‘logout‘);10         $action = $this->getAction()->getId();11         if(!in_array($action, $blackList)){12             parent::init();13         }14         return TRUE;15     }



 

 

    protected $userId = 0;        public function init()    {        header(‘Content-type:text/html;charset=utf-8‘);        Yii::import(‘ext.functions‘, true); //加载公共函数        $this->getUserId();    }        //获取用户    protected function getUserId()    {        $userTicket = getRParam(‘ticket‘, ‘‘);        Yii::app()->ssoClient->init($userTicket);        $this->userId = (int)Yii::app()->ssoClient->userid;    }        public function filters()    {        return array(‘CheckLogin - login, registe, logout‘);    }        public function filterCheckLogin($chain)    {        if($this->userId > 0)            $chain->run();        else            $this->ajaxError(100, ‘用户验证失败或已过期‘);    }    

 

Yii 动作过滤的方法