Summary of commonly used system variables in Thinkphp templates_PHP tutorial

WBOY
Release: 2016-07-13 10:31:03
Original
856 people have browsed it

The Thinkphp template engine can directly output some system variables, system constants, and system special variables without assigning a value to a template variable. The output of system variables must start with $Think. and can still support the use of functions. Let’s share them separately.

(1) System variables : Output system variables in the template: including 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: Use $Think.const to output

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

{$Think.server.script_name} and {$Think.SERVER.script_name} are equivalent

SESSION and COOKIE 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 array output of more than three dimensions.


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

{$Think.lang.page_error}

{$Think.const.MODULE_NAME}

or use directly

{$Think.MODULE_NAME}

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

{$Think.version} //Version

{$Think.now} //Now time

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

{$Think.LDELIM} //Template label starting symbol

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

(4) Configuration parameter : Output the configuration parameter value of the project

{$Think.config.db_charset}

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

(5) thinkphp system constants (note that the following constants can also be used directly in the action controller)

__ROOT__ // Website root directory address

__APP__ // Current project (entry file) address

__URL__ // Current module address

__ACTION__ // Current operation address

__SELF__ // Current URL address

__PUBLIC__ // Website public directory

Articles you may be interested in

  • Summary of system constants in thinkphp’s Action controller
  • ThinkPHP built-in template engine Summary of usage
  • Using php functions in smarty templates and how to use multiple functions on one variable in smarty templates
  • Judge the last record of volist loop in thinkphp template
  • How to generate random numbers in smarty templates
  • Commonly used functions for judging variables in PHP
  • The difference between execute and query methods in ThinkPHP
  • thinkphp prints the last sql statement

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764146.htmlTechArticleIn Thinkphp template engine, you can directly output some system variables and system constants without assigning a value to a template variable, and System special variables. The output of system variables must start with...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template