Thinkphp5.1 method to get the project root directory and subdirectory path

Introduction:

I recently used Thinkphp5.1 for development, and an error occurred when using the LOG_PATH constant (log path). Because I have been using the 5.0 framework before, after switching to version 5.1, this situation occurred. I understand that the official adjustment has been made, so I went there Read the official instructions.

Official document: https://www.kancloud.cn/manual/thinkphp5_1/

Constant adjustment

Thinkphp5.1 cancels all built-in constants in the framework (does not affect custom constants in the application code). If you need to obtain them, please use the built-in methods of the think\facade\App class and the think\facade\Env class to obtain them.

5.0 Constant 5.1 How to Obtain
EXT Cancel, use .php
IS_WIN cancel
IS_CLI cancel
DS Use PHP comes with DIRECTORY_SEPARATOR
ENV_PREFIX Cancel, use PHP_
THINK_START_TIME App::getBeginTime()
THINK_START_MEM App::getBeginMem()
THINK_VERSION App::version()
THINK_PATH Env::get(‘think_path’)
LIB_PATH Env::get(‘think_path’) . ‘library/’
CORE_PATH Env::get(‘think_path’) . ‘library/think/’
APP_PATH Env::get(‘app_path’)
CONFIG_PATH Env::get(‘config_path’)
CONFIG_EXT App::getConfigExt()
ROOT_PATH Env::get(‘root_path’)
EXTEND_PATH Env::get(‘root_path’) . ‘extend/’
VENDOR_PATH Env::get(‘root_path’) . ‘vendor/’
RUNTIME_PATH Env::get(‘runtime_path’)
LOG_PATH Env::get(‘runtime_path’) . ‘log/’
CACHE_PATH Env::get(‘runtime_path’) . ‘cache/’
TEMP_PATH Env::get(‘runtime_path’). ‘temp/’
MODULE_PATH Env::get(‘module_path’)

Note: When obtaining path variables through the get method of the Env class, it is not case sensitive.

Thinkphp5.1 method to print independent log:

/** 
 * 打印日志
 * $msg 日志内容
 */
function printLog($msg) {
    
    
	$path=LOG_PATH .date('Y-m-d').".txt";
	file_put_contents($path, "【" . date('Y-m-d H:i:s') . "】\r\n" . $msg . "\r\n\r\n", FILE_APPEND);
}

Guess you like

Origin blog.csdn.net/qq15577969/article/details/114372000