Use Smarty 3 in PHP: keep variable in Smarty _ PHP Tutorial

Source: Internet
Author: User
Use Smarty 3 in PHP: reserved variable in Smarty. There are some reserved variables in Smarty, which can be directly used without the PHP script for allocation, that is, $ _ tpl-assign (var, value) for allocation. 1. visit the page in the template. there are some reserved variables in Smarty. they can be directly used without being allocated by the PHP script, you do not need to use $ _ tpl-> assign ('var', 'value') for allocation.

1. variables used to access the page request in the template

{$ Smarty. get. user }== _ GET ['user']

{$ Smarty. post. user }== _ POST ['user']

{$ Smarty. cookie. username }== _ COOKIE ['username']

{$ Smarty. session. username }== _ SESSION ['username']

{$ Smarty. server. REMOTE_ADDR }== _ SERVER ["REMOTE_ADDR"]

{$ Smarty. env. PATH }== _ ENV ['path']

{$ Smarty. request. username }== _ REQUEST ['username']

2. access the constants and system constants defined in the PHP script in the template file.

{$ Smarty. const. _ FILE __} current PHP FILE

{$ Smarty. const. CONST_VAR} accesses the constant defined by define in the PHP script.

3. get the time of the current server in the template file

{$ Smarty. now | date_format: "% Y-% m-% d % H: % M: % S" }== date ('Y-m-d H: I: s ', time ())

4. access the configuration file in the template

You can use {$ smarty. config. configuration variable} to access the Template variables in the configuration file. In this way, there are two methods to access the variables in the configuration file in the Template: 1. {# configuration variable #}; 2. {$ smarty. config. configuration variable}. this is also true if there is a region.

5. obtain the data captured by the Smarty built-in function capture.

The capture function captures the data output from the template and stores the data in a variable instead of outputting the data to the page, any data between {capture name = "foo"} and {/capture} is stored in the variable $ foo, which is specified by the name attribute. Access the variable through $ smarty. capture. foo in the template. if the name attribute is not specified, the function uses "default" as the parameter by default.


From: Lee.'s column

There are some reserved variables, which can be directly used without the PHP script for allocation, that is, $ _ tpl-assign (var, value) for allocation. 1. visit the page in the template...

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.