1)创建BaseController控制器继承Controller(后台的一切操作要继承BaseController):
在BaseController里面添加:
代码如下:
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) {
echo json_encode(array('code' => -101,'message' => '用户未登录。','callback' => 'window.location="' . $url . '";'));
} else if (Yii::app()->request->isAjaxRequest) {
echo '
$url = $this->createUrl('user/login');
if (Yii::app()->request->isPostRequest && Yii::app()->request->isAjaxRequest) {
echo json_encode(array('code' => -101,'message' => '用户未登录。','callback' => 'window.location="' . $url . '";'));
} else if (Yii::app()->request->isAjaxRequest) {
echo '