1) Create a BaseController controller and inherit the Controller (all background operations must inherit the BaseController):
Add in BaseController:
Copy code The code is as follows:
public function checkLogin() {
if (Yii::app ()->authority->isLogin() == Yii::app()->authority->getStatus('NOTLOGIN')) {
$url = $this->createUrl('user /login');
if (Yii::app()->request->isPostRequest && Yii::app()->request->isAjaxRequest) { code' => -101, 'message' => 'The user is not logged in ', 'callback' => 'window.location="' . $url . '";'));
} else if (Yii::app()->request->isAjaxRequest) {
echo ' { Return true;
}
Create the Authority.php file in the components directory:
Copy code
The code is as follows:
/** * Permission check component
*/
class Authority extends CComponent {
private $NOTLOGIN = -1;
private $FAILED = -2;
private $PASS = 1;
public function init() {
}
/**
* Check if you are logged in
* @return boolean
*/
function isLogin() {
return isset(Yii::app()->session['user']) ? $this->PASS : $this->NOTLOGIN;
}
/**
* Get status value
* @param string $name
* @return int
*/
public function getStatus($name){
return $this->$name;
}
}
http://www.bkjia.com/PHPjc/824850.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/824850.htmlTechArticle1) Create a BaseController controller to inherit the Controller (all background operations must inherit the BaseController): Add in the BaseController: Copy The code is as follows: public function check...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn