_javascript techniques of system constants and system variables commonly used in thinkphp

Source: Internet
Author: User
Tags current time md5 memory usage

----------------------------------------the system variables and constants used in the template----------------------------------------
(1) System Variables : Output system Variables in a template: Include server, env, session, post, get, request, cookie
{$Think. Server.script_name}//Output $_server variable
{$Think. SESSION.SESSION_ID|MD5}//Output $_session variable
{$Think. Get.pagenumber}//Output $_get variable
{$Think. Cookie.name}//Output $_cookie variable

The above method can also be written as:
{$_server.script_name}//Output $_server variable
{$_SESSION.SESSION_ID|MD5}//Output $_session variable
{$_get.pagenumber}//Output $_get variable
{$_cookie.name}//Output $_cookie variable

System constants: using $think.const output
Note: Server, cookie, config is case-insensitive, but variables are case-sensitive. For example:
{$Think. Server.script_name} and {$Think. Server.script_name} are equivalent
Session, cookies also support the output of two-dimensional arrays

For example:
{$Think. CONFIG.user.user_name}
{$Think. Session.user.user_name}
The system does not support more than three-dimensional array output.

(2) language variable: output the current language definition value of an 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}//Present time
{$Think. Template|basename}//Template page
{$Think. Ldelim}//template label start symbol
{$Think. Rdelim}//template tag end symbol
(4) configuration parameter: Output item's configuration parameter value

{$Think. Config.db_charset}

The output value is the same as the result of C (' Db_charset ').

----------------------------------------the system constants used in the action----------------------------------------
Think_path//thinkphp system directory
App_path//Current project directory
App_name//Current project name
Module_name//Current module name
Action_name//Current operation name
Tmpl_path//Project templates Catalog
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 Files directory
Plugin_path//Project plug-in file directory
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 belong to FREEBSD environment
Now_time//Current time stamp
MEMORY_LIMIT_ON//Whether there is a memory usage limit
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__//Site root directory Address
__APP__//Current project (entry file) address
__URL__//Current module address
__ACTION__//Current operation address
__self__//Current URL address
Tmpl_file_name//Default template name for current operation (including path)
Web_public_url//web site Public directory
App_public_url//Project Public template Catalog
----------------------------------------the system constants used in the template----------------------------------------
__root__//Site root directory Address
__APP__//Current project (entry file) address
__URL__//Current module address
__ACTION__//Current operation address
__self__//Current URL address
__public__//web site Public directory
.. /public (case-insensitive)//Project Public template Catalog
Note: When we use constants, after the template is loaded in the browser to view the source code, we observe some use of the constant URL, we will find a phenomenon, the server's IP address is not seen, URL is from the item
The first name starts, then why can the correct access to the corresponding controller? In fact, this is the browser to give us a joke, when we move the mouse to the URL, click the right button, copy the source code in the
URL, paste to another place, the server's IP will be displayed, the visible server IP is included in the URL used in the constant.
----------------------------------------Custom Constants----------------------------------------
Create a new common.php under the common folder in the project folder (such as: Home)
Add the following statement:
Define (' xxx ', xxx); The first argument is a constant name, and the second argument is a 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.