thinkphp5 Method for Loading Static Resource Paths and Constants

  • 2021-08-21 20:02:50
  • OfStack

1. Load the static resource path

Versions greater than 5.0. 4 can be used directly

__ROOT__: Project Directory

__STATIC__: static directory under project directory

__JS__: static/js Directory under Project Directory

__CSS__: The static/css directory under the project directory

We can use the view template to print the specific paths of these constants


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
__ROOT__<br>
__STATIC__<br>
__JS__<br>
__CSS__<br>
</body>
</html>

The page output is as follows:


/
/projectname/public/static
/projectname/public/static/js
/projectname/public/static/css

Open the application folder under the config file, you can customize resource constants according to your own needs, after the definition of constants can be used in the template file constants.

For example:


<?php
return [ 
 'view_replace_str' => [ 
  '__PUBLIC__'=>'../public/static/admin',
  '__ROOT__' => '/',
  '__APP__' => 'app/admin/',
 ]
];

2. Predefined constants

Predefined constants refer to the defined constants built into the system, which will not change with the change of environment, including:

EXT Class Library File Suffix (. php)

THINK_VERSION Framework Version Number

3. Path constants

The system and application path constants are used for the system default directory specification, and can be changed by redefinition. If you do not want to customize the directory, these constants 1 generally do not need to be changed.


DS  Directory separator for the current system 
THINK_PATH  Framework system directory  
ROOT_PATH  Framework application root directory 
APP_PATH  Application directory (default is application ) 
CONF_PATH  Configuration directory (default is APP_PATH ) 
LIB_PATH  System class library directory (default is  THINK_PATH.'library/' ) 
CORE_PATH  System core class library directory   (Default to  LIB_PATH.'think/' ) 
TRAIT_PATH  System trait Directory (default is  LIB_PATH.'traits/' ) 
EXTEND_PATH  Extended class library directory (default is  ROOT_PATH . 'extend/')
VENDOR_PATH  No. 1 3 Square class library directory (default is  ROOT_PATH . 'vendor/' ) 
RUNTIME_PATH  Application runtime directory (default is  ROOT_PATH.'runtime/' ) 
LOG_PATH  Application log directory   (Default to  RUNTIME_PATH.'log/' ) 
CACHE_PATH  Project template cache directory (default is  RUNTIME_PATH.'cache/' ) 
TEMP_PATH  Apply cache directory (default is  RUNTIME_PATH.'temp/' ) 

4. System constants

System constants will change with the change of development environment or settings.


IS_WIN  Whether it belongs to Windows  Environment  
IS_CLI  Is it in command line mode  
THINK_START_TIME  Start running time (timestamp) 
THINK_START_MEM  Memory usage at the beginning of running 
ENV_PREFIX  Environment variable configuration prefix 

Summarize

The above is the site to introduce you to the thinkphp5 loading static resource path and constant method, I hope to help you, if you have questions welcome to leave me a message, this site will reply to you in time!


Related articles: