How to use smarty template engine to configure and retain data
This article mainly introduces "how to use smarty template engine configuration file data and retain data". In daily operation, I believe many people have doubts about how to use smarty template engine configuration file data and retain data. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to use smarty template engine configuration file data and retain data". Next, please follow the editor to study!
The details are as follows:
First, how to make the template extract data directly from the configuration file
1. Use occasion
When the value of a variable does not want to be written directly into the program (through smarty allocation), it can be obtained through the configuration file.
two。 Write configuration file
Create a new folder: config
Create a new file name: my.ini or my.config
Content: key=value
Example:
Title= "This is the title of the website." bgcolor= "pink"
3. Usage
Load configuration file: {config_laod file= "path"}
Use profile data:
Example:
{config_laod file= "my.config"}.
Second, how to obtain the data of reserved variables
That is, how to get get/post/session/server data. This data is stored in an array, and smarty encapsulates the method, which can be obtained directly through the smarty variable.
1. Get get data
The traditional way is to get get data first, and then assign it to smarty. But smarty itself encapsulates the method, and you can get get data directly without allocation.
The method of use is as follows:
User name: password:
two。 Get post data
The method of use is as follows:
User name: password:
3. Get server data
The method of use is as follows:
Server name: at this point, the study on "how to use the smarty template engine to configure file data and retain data" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!