In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to achieve smarty in php, which is very detailed and has a certain reference value. Interested friends must read it!
In PHP, smarty is a template engine written in PHP, which provides an easy-to-manage and easy-to-use method to logically separate the PHP code originally mixed with HTML code, so as to improve the speed of programs written in smarty.
This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer
Smarty concept: what is Smarty?
Smarty is a template engine written in PHP language, and it is one of the most famous PHP template engines in the industry. It separates logical code from external content, and provides an easy-to-manage and easy-to-use way to logically separate PHP code that was originally mixed with HTML code. To put it simply, the purpose is to separate the PHP programmer from the front-end staff, so that the programmer changes the logical content of the program will not affect the front-end staff's page design, and the front-end staff re-modify the page will not affect the program logic, which is particularly important in multi-person cooperation projects.
What are the characteristics of Smarty?
1. Fast (because the second execution uses the compiled file generated on the first execution)
2. Caching technology (it is because of caching technology that smarty template technology is not suitable for those with high requirements for real-time updates, such as stock information)
3. Plug-in technology
4. Caching technology
5. Statement free static page technology is actually a technology of exchanging space for time.
Smarty object-oriented implementation template function encapsulation:
/ / define Smarty class class Smarty {/ * Save template corresponding tag data * @ var array*/private $tplData = array (); / * set data for template tag attributes * @ param sting $key corresponding template tag signature * @ param mixed $val corresponding template tag value * @ return*/public function assign ($key, $val) {$this- > tplData [$key] = $val } / * generate compilation file * @ param string $tpl template file (name + suffix) * @ return*/public function display ($tpl) {/ / generate compilation file / / or / / template file last modification time > build file creation time regenerate compilation file if (! file_exists ("$tpl.php") | | filemtime ($tpl) > filemtime ("$tpl.php") {/ / 1. Get the template file data $htmlData = file_get_contents ($tpl); / / 2. Replace template tag / / replace {$title} / /
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.