时时商务社区

标题: php后台如何避免用户直接进入方法实例 [打印本页]

作者: xgnic    时间: 2018-2-14 08:11

            1)创建BaseController控制器继承Controller(后台的一切操作要继承BaseController):
在BaseController里面添加:
[U]复制代码[/U] 代码如下:
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 '';
            } else {
                $this->redirect($url);
            }
            exit;
        }
        return true;
    }
在components目录下创建Authority.php文件:
[U]复制代码[/U] 代码如下:
session['user']) ? $this->ASS : $this->NOTLOGIN;
    }
   
    /**
     * 获取状态值
     * @param string $name
     * @return int  
     */
    public function getStatus($name){
        return $this->$name;
    }
}
            
            
您可能感兴趣的文章:
  • php后台多用户权限组思路与实现程序代码分享
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2