This article mainly introduces the post usage in smarty, and analyzes in detail the implementation process of POST in smarty in the form of instances, including the call of the configuration file and the implementation of the template file, for more information about post usage in smarty, see the following example. Share it with you for your reference. The specific analysis is as follows:
After learning the operating principle of smarty, I want to write a post implementation process. The following is the post implementation code, which is similar to the php code written by myself. it only adds more Display files.
Configuration File: conf. php
The code is as follows:
<? Php
@ Header ("Content-type: text/html; charset = UTF-8 ");
Require '../libs/Smarty. class. php ';
$ My = new Smarty;
$ My-> template_dir = 'Templates /';
$ My-> compile_dir = 'Templates _ c /';
$ My-> config_dir = 'configs /';
$ My-> cache_dir = 'cache /';
?>
Index. php
The code is as follows:
<? Php
Include 'conf. php ';
$ My-> assign ('content', 'Welcome to arrival ');
$ My-> assign ('mylife', array ("Life", "dinner", "dream", "Liangfeng", "Revenge", "fuck someone ", "fuck you die "));
$ My-> display('kk.html ');
?>
Kk.html under template[ index. php display file]
The code is as follows:
Untitled Document
{$ Content}
{Section name = truelife loop = $ mylife}
{$ Mylife [truelife]}
{/Section}
{Html_select_time use_24_hours = true}
Submit. php
The code is as follows:
<? Php
Include 'conf. php ';
$ Kk = $ _ POST ['conteng'];
$ Ct = $ _ POST ['CT '];
$ Sm = new Smarty ();
$ Sm-> assign ('content', $ kk );
$ K = explode ("\ r \ n", $ ct); // separate characters into arrays
$ Sm-> assign ('ml', $ k );
$ Sm-> display ('M. tpl ');
?>
M. tpl file under template [display file of submit. php]
The code is as follows:
{$ Content}
{Section name = kk loop = $ ml}
{$ Ml [kk]}
{/Section}
I hope this article will help you design your smarty program.