/****************************************************************************** * PHP Smarty Temp Late for Website * Description: * have been thinking of MVC in the way to add to PHP Web site, so better processing, relatively good * processing, so follow-up maintenance will be better. * 2017-3-12 Shenzhen Nanshan Ping Shan village Zengjianfeng ******************************************************* **********************/First, reference documents:1. Smarty Tutorial http://www.yiibai.com/smarty/ 2. Smarty Template engine http://www.smarty.net/ 3. Parsing JSON file with PHP http://stackoverflow.com/questions/4343596/parsing-json-file-with-phpSecond, Smarty Download:1. GZ File:https://github.com/smarty-php/smarty/archive/v3.1.30.tar.gz 2. Zip File:https://Github.com/smarty-php/smarty/archive/v3.1.30.zipThree, configuration:1. Use relative paths to join the current project;2. Using require_once ('<path to Smarty.class.php>'): <?PHP//Note:smarty have a capital ' S 'Require_once ('<path to Smarty.class.php'); $smarty=NewSmarty (); ?>3. Template file suffix name: <file name>. TPL4. Note: {* Comments *} 5. Assignment variables: $smarty->assign ('name','Ned'); 6. Processing templates: $smarty->display ('INDEX.TPL'); 7. Open Debug mode: $smarty->debugging =true; 8. Inherit class Smarty, extended functionality:<?PHP//Load Smarty LibraryRequire'Smarty.class.php'); //The setup.php file is a good place to load//required Application library files, and you//can do. An example://require (' guestbook/guestbook.lib.php '); classSmarty_guestbook extends Smarty {function __construct () {//Class Constructor. //these automatically get set with the each new instance.parent::__construct (); $ This->settemplatedir ('/web/www.example.com/guestbook/templates/'); $ This->setcompiledir ('/web/www.example.com/guestbook/templates_c/'); $ This->setconfigdir ('/web/www.example.com/guestbook/configs/'); $ This->setcachedir ('/web/www.example.com/guestbook/cache/'); $ This->caching =smarty::caching_lifetime_current; $ This->assign ('app_name','Guest Book'); } } ?>9. Inherit using:<?php require ('guestbook/setup.php'); $smarty=NewSmarty_guestbook (); $smarty->assign ('name','Ned'); $smarty->display ('INDEX.TPL'); ?>Ten. Parse the JSON file when the configuration file, put the data into the Smarty object, so it is well configured.
PHP Smarty template for website