Common system constants and system variables in thinkphp

Source: Internet
Author: User

Common system constants and system variables in thinkphp

This article mainly introduces common system constants and variables in thinkphp. If you need them, refer

-------------------------------------- System variables and constants used in the template ----------------------------------------

(1) system variables: Output System variables in the template, including server, env, session, post, get, request, and cookie

{$ Think. server. script_name} // output the $ _ SERVER variable.

{$ Think. session. session_id | md5} // output the $ _ SESSION variable.

{$ Think. get. pageNumber} // output the $ _ GET variable.

{$ Think. cookie. name} // output $ _ COOKIE variable

The preceding method can also be written as follows:

{$ _ SERVER. script_name} // output $ _ SERVER variable

{$ _ SESSION. session_id | md5} // output the $ _ SESSION variable.

{$ _ GET. pageNumber} // output the $ _ GET variable.

{$ _ COOKIE. name} // output $ _ COOKIE variable

System constant: output with $ Think. const

Note: server, cookie, and config are case-insensitive, but variables are case-sensitive. For example:

{$ Think. server. script_name} is equivalent to {$ Think. SERVER. script_name }.

SESSION and COOKIE support two-dimensional array output

For example:

{$ Think. CONFIG. user. user_name}

{$ Think. session. user. user_name}

The system does not support array output of more than three dimensions.

(2) language variable: the current language definition value of the output project

{$ Think. lang. page_error}

{$ Think. const. MODULE_NAME}

Or directly use

{$ Think. MODULE_NAME}

(3) special variables: constants defined in the ThinkPHP System

{$ Think. version} // version

{$ Think. now} // current time

{$ Think. template | basename} // template page

{$ Think. LDELIM} // template tag start symbol

{$ Think. RDELIM} // template tag end symbol

(4) configuration parameters: Configuration Parameter Values of the output project

{$ Think. config. db_charset}

The output value is the same as that of C ('db _ charset.

---------------------------------------- System constant used in Action ----------------------------------------

THINK_PATH // ThinkPHP system directory

APP_PATH // current project directory

APP_NAME // current project name

MODULE_NAME // name of the current Module

ACTION_NAME // current operation name

TMPL_PATH // Project template directory

LIB_PATH // directory of the Project class library

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 // temporary project file directory

PLUGIN_PATH // directory of the Project plug-in file

VENDOR_PATH // third-party class library directory

DATA_PATH // project data file directory

IS_APACHE // whether it belongs to Apache

IS_IIS // whether it belongs to IIS

IS_WIN // whether it belongs to the Windows Environment

IS_LINUX // whether it belongs to the Linux environment

IS_FREEBSD // whether it belongs to the FreeBsd Environment

NOW_TIME // current Timestamp

MEMORY_LIMIT_ON // whether the memory usage limit exists

OUTPUT_GZIP_ON // whether to enable output Compression

MAGIC_QUOTES_GPC // MAGIC_QUOTES_GPC

THINK_VERSION // ThinkPHP version

LANG_SET // browser Language

TEMPLATE_NAME // name of the current template

TEMPLATE_PATH // current template path

_ ROOT _ // website ROOT directory address

_ APP _ // current project (entry file) Address

_ URL _ // address of the current Module

_ ACTION _ // current operation address

_ SELF _ // current URL

TMPL_FILE_NAME // default Template Name (including path) for the current operation)

WEB_PUBLIC_URL // public website directory

APP_PUBLIC_URL // Project Public template directory

---------------------------------------- System constant used in the template ----------------------------------------

_ ROOT _ // website ROOT directory address

_ APP _ // current project (entry file) Address

_ URL _ // address of the current Module

_ ACTION _ // current operation address

_ SELF _ // current URL

_ PUBLIC _ // PUBLIC website directory

../Public (Case Insensitive) // Project Public template directory

Note: When we use constants, we can view the source code in the browser after the template is loaded. We can observe some URLs that use constants and we will find a phenomenon that we cannot see the IP address of the server, the URL is from

Why can I access the corresponding Controller correctly? In fact, this is a joke from the browser. When we move the mouse over the URL, right-click and copy

URL, paste it to another place, and the server's ip address will be displayed. It can be seen that the server ip address is included in the constant used in the URL.

---------------------------------------- Custom constant ----------------------------------------

Create Common. php under the common folder in the project folder (for example, Home)

Add the following statement:

Define ('xxx', XXX); // The first parameter is the constant name, and the second parameter is the constant value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.