Configuration file data and retention data of the smarty template engine
This article mainly introduces the configuration file data and data retention methods of the smarty template engine. The example analyzes the configuration file data of the smarty template engine and the specific techniques for getting data, which has some reference value, for more information, see
This document describes the configuration file data and data retention methods of the smarty template engine. Share it with you for your reference. The details are as follows:
1. How to retrieve data from the configuration file directly
1. application scenarios
When a variable value is not directly written to the Program (allocated by smarty), it can be obtained through the configuration file.
2. Write the configuration file
Create a folder: config
New File Name: my. ini or my. config
Content: key = value;
Example:
?
1 2 |
Title = "This is the title of the website ." Bgcolor = "pink" |
3. Usage
Load the configuration file: {config_laod file = "path "}
Use the configuration file data: <{# key #}>
Example:
?
1 2 |
{Config_laod file = "my. config "} <Body bgcolor = '<{# bgcolor #}>'>... </body> |
2. How to obtain data with reserved Variables
That is, how to obtain get/post/session/server data. The data is saved in the array. smarty encapsulates the method and can be obtained directly through the smarty variable.
1. get Data
Traditional Method: get data first and distribute it to smarty. However, smarty encapsulates methods and can directly obtain get data without assigning them.
The usage is as follows:
?
1 2 |
Username: <{$ smarty. get. username}> <br/> Password: <{$ smarty. get. password}> <br/> |
2. Get post Data
The usage is as follows:
?
1 2 |
Username: <{$ smarty. post. username}> <br/> Password: <{$ smarty. post. password}> <br/> |
3. Obtain server data
The usage is as follows:
?
1 |
Server Name: <{$ smarty. server. SERVER_NAME}> |
I hope this article will help you with php programming.