<?php namespace app\admin\common; use think\Controller; use think\Session; class Base extends Controller { protected function _initializa() { parent::_initializa(); //在公共控制器的初始化方法中,創(chuàng)建一個(gè)常量來判斷用戶是否登錄或已登錄 define('USER_ID',Session::get('user_id')); } //判斷用戶是否登錄,在后臺(tái) protected function islogin() { //如果登錄常量為null,表示沒有登錄 if (is_null('USER_ID')) { $this -> error('未登錄,無權(quán)訪問!','login/index'); } } //如果用戶已經(jīng)登錄,將不允許再次登錄 protected function alreadyLogin() { //如果登錄常量為null,表示沒有登錄 if (!is_null(USER_ID)) { $this -> error('已經(jīng)登錄,不要重復(fù)登錄~~', 'index/index'); } } }
When accessing the background, it prompts the undefined constant USER_ID,
Logically speaking, it is in front define('USER_ID',Session::get('user_id')) ; The constant has already been defined. Why is this prompt
Thank you everyone, the problem has been found