ThinkPHP5 quickly develops corporate sites
清雨
清雨 2017-09-26 09:22:57
0
2
1223
<?php
namespace app\admin\common;
use think\Controller;
use think\Session;

class Base extends Controller
{
    protected function _initializa()
    {
        parent::_initializa();
        //在公共控制器的初始化方法中,创建一个常量来判断用户是否登录或已登录
        define('USER_ID',Session::get('user_id'));
    }
    //判断用户是否登录,在后台
    protected function islogin()
    {
        //如果登录常量为null,表示没有登录
        if (is_null('USER_ID')) {
            $this -> error('未登录,无权访问!','login/index');
        }
    }
    //如果用户已经登录,将不允许再次登录
    protected function alreadyLogin()
    {
        //如果登录常量为null,表示没有登录
        if (!is_null(USER_ID)) {
            $this -> error('已经登录,不要重复登录~~', 'index/index');
        }
    }

}

When accessing the background, it prompts the undefined constant USER_ID,

微信截图_20170926092140.png

Logically speaking, it is in front define('USER_ID',Session::get('user_id')) ; The constant has already been defined. Why is this prompt

清雨
清雨

reply all(1)
清雨

Thank you everyone, the problem has been found

  • reply Dear, what is the problem and how to solve it. Solve
    phpcn1111 author 2018-02-02 10:45:43
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template