System constants and system variables commonly used in thinkphp

  • 2020-03-30 02:12:38
  • OfStack

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- template variables and constants used in the system -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
(1) system variables : output system variables in the template: including server, env, session, post, get, request, cookie&cake;        
{$think.server.script_name} // output $_SERVER variable
{$think.session_id |md5}
{$think.get.pagenumber} // output $_GET variable  
{$Think. The cookie. The name}   // output $_COOKIE variable

The above methods can also be written:
{$_server.script_name} // output $_SERVER variable
{$_session_id |md5}
{$_get.pagenumber} // output $_GET variable  
{$_COOKIE. Name}   // output $_COOKIE variable

(2) language variables: Output the current language definition value of the item

{$Think. Lang. Page_error}
{$Think. Const. MODULE_NAME}

Or use it directly
{$Think. MODULE_NAME}

(3) special variables: Constants defined internally by the ThinkPHP system

{$Think. Version}   / / version
{$think.now} // current time    
{$think.template |basename} // template page    
{$think.ldelim} // template tag start symbol & somalia;  
{$think.rdelim} // template tag closing symbol
(4) configuration parameter: output the configuration parameter value of the project

{$Think. Config. Db_charset}

The output value is the same as that of C('db_charset').

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the Action constants used in the system -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
THINK_PATH // ThinkPHP system directory
APP_PATH // current project directory
APP_NAME // current project name
MODULE_NAME // current module name
ACTION_NAME // current action name
TMPL_PATH // project template directory
LIB_PATH // project class library directory
CACHE_PATH // project template cache directory
CONFIG_PATH // project configuration file directory
LOG_PATH // project log file directory
LANG_PATH // project language file directory
TEMP_PATH // project temporary file directory
PLUGIN_PATH // project plug-in file directory
VENDOR_PATH // third party library directory
DATA_PATH // project data file directory
IS_APACHE // belongs to Apache
IS_IIS // whether it belongs to IIS
Is IS_WIN // part of the Windows environment
IS_LINUX // whether it belongs to the Linux environment
IS_FREEBSD // is it part of the FreeBsd environment
NOW_TIME // current timestamp
MEMORY_LIMIT_ON // whether there are memory usage limits
OUTPUT_GZIP_ON // whether to turn on output compression
MAGIC_QUOTES_GPC / / MAGIC_QUOTES_GPC
THINK_VERSION //ThinkPHP version number
LANG_SET // browser language
TEMPLATE_NAME // current template name
TEMPLATE_PATH // current template path
// root directory address of website
// current project (entry file) address
// s/current module address
S // current action address
S // current URL address
TMPL_FILE_NAME // default template name for current operation (including path)
WEB_PUBLIC_URL // website public directory
APP_PUBLIC_URL // project public template directory
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the template system used in constant -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// root directory address of website
// current project (entry file) address
// s/current module address
S // current action address
S // current URL address
// website public directory
. // project Public template directory
Note: when we use constants, after the template is loaded in the browser to view the source code, we observe some use of constants in the URL, will find a phenomenon, can not see the server's IP address, URL from the item
The name of the object starts, so why is the corresponding controller accessed correctly? This is actually a joke the browser made for us when we moved the mouse over the URL, right-click, and copied the source code
The URL, paste it somewhere else, and the server's IP will be displayed, so that the server's IP is included in the constants used in the URL.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- custom constants -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
Create common.php under the Common folder in the project folder, such as Home
Add the following statement:
Define (' XXX ', XXX); // the first parameter is the constant name and the second parameter is the constant value


Related articles: