search

Home  >  Q&A  >  body text

ThinkPHP5 quickly develops corporate sites

<?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

清雨清雨2687 days ago1271

reply all(2)I'll reply

  • 清雨

    清雨2017-09-26 09:37:32

    Thank you everyone, the problem has been found

    reply
    1
  • phpcn1111

    Dear, what is the problem and how to solve it. Solve

    phpcn1111 · 2018-02-02 10:45:43
  • Cancelreply