"Smarty Video tutorial" will show you how to implement code separation. Smarty is one of the most famous PHP template engines in the industry today. It separates the logic code from the external content, provides an easy-to-manage and useful way to separate the PHP code that was originally mixed with HTML code. Simply put, the goal is to make the PHP programmer and the front-end personnel separate, so that the work of the two will not affect each other!
Course Play Address: http://www.php.cn/course/353.html
The teacher's lecture style:
The lectures are kind and natural, unpretentious, no affectation, nor deliberately rendered, but instilled, careful way, between teachers and students in a kind of equality, cooperation, harmonious atmosphere, the silent emotional exchange, the thirst for knowledge and exploration into a simple, real teaching situation, students in the quiet thinking, To gain knowledge in silent consent
The most difficult part of this video is the smarty-cache:
(1) Page cache: entire page global cache
4 Steps Required:
① Open Cache $smarty->caching = true;
② set the life cycle of the cache $smarty->cache_lifetime = 3600;
③ Set Cache directory $smarty->cache_dir = './cache ';
④ settings to fetch data from the database only when there is no cache
if (! $smarty->iscached (' template name ')) {//Fetch data from database and assign assignment}
(2) Local not cache
On the basis of the entire page cache, some parts of the page are not cached and need to be updated in a timely manner. such as time, stock information and so on. So it's necessary to control the local not caching. There are 4 ways: To pass the template in a PHP file to a timestamp as an example:
<?php//Omit other code $smarty->assign (' Time ', Time ());? >
① Single Label Control
Using NoCache in the label of the template, you can control that the tag is not cached, as follows:
{$time NoCache}
②nocache Label Pairs
In the {Nocache}{/nocache} tag inner zone, you can implement no caching
Like what
{NoCache} {$time 1} {$time 2} {/nocache}
This way, two tags $time1 and $time2 are not cached
③ control when the assign is assigned to a value
In PHP, when assigning a value to a template tag using the Assign method, the first parameter is the label name, the second parameter is the value, and the third parameter is optional. True if the given third argument indicates that the label is not cached
$smarty->assign (' time ', $time, true);
The {$time} tag in the template is not cached
④ to get the return value of the corresponding function in PHP by the Insert method
The specific syntax is: the label of {insert name= ' xxx '} in the template can get the return value of the insert_xxx () function in the PHP file.
For example: The code in the template file:
{Insert name= ' time '}
Here also recommend the source of resources to download: http://www.php.cn/xiazai/learn/2113
Resources inside to share the video courseware, PPT and source code