zoukankan      html  css  js  c++  java
  • PHP Smarty template for website

    /******************************************************************************
     *                        PHP Smarty template for website
     * 说明:
     *     之前一直在想将MVC的方式加在PHP做的网站上,这样比较好处理,相对来说比较好
     * 处理,这样后续维护会比较好。
     *
     *                                         2017-3-12 深圳 南山平山村 曾剑锋
     *****************************************************************************/
    
    一、参考文档:
        1. Smarty教程
            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-php
    
    二、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.zip
        
    三、配置:
        1. 使用相对路径加入当前项目;
        2. 使用require_once('<path to Smarty.class.php>'):
            <?php
            // NOTE: Smarty has a capital 'S'
            require_once('<path to Smarty.class.php');
            $smarty = new Smarty();
            ?>
        3. template文件后缀名: <file name>.tpl
        4. 注释:
            {* comments *}
        5. 赋值变量:
            $smarty->assign('name','Ned');
        6. 使用:
            {$name}
        7. 处理模板:
            $smarty->display('index.tpl');
        8. 打开debug模式:
            $smarty->debugging = true;
        9. 继承class smarty,扩展功能:
            <?php
    
            // load Smarty library
            require('Smarty.class.php');
    
            // The setup.php file is a good place to load
            // required application library files, and you
            // can do that right here. An example:
            // require('guestbook/guestbook.lib.php');
    
            class Smarty_GuestBook extends Smarty {
    
               function __construct()
               {
    
                    // Class Constructor.
                    // These automatically get set with 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');
               }
    
            }
            ?>
        10. 继承使用:
            <?php
    
            require('guestbook/setup.php');
    
            $smarty = new Smarty_GuestBook();
    
            $smarty->assign('name','Ned');
    
            $smarty->display('index.tpl');
            ?>
        11. 解析JSON文件当配置文件,将数据放入smarty对象中,这样就好配置了。
  • 相关阅读:
    Collections集合工具类排序
    集合的学习
    gitee使用方法
    vue 首屏优化
    vue 配置多个路由别名
    vue中的状态管理Vuex
    【Python】Pandas合并表格之(append, join , concat方法)
    elementui中提交表单自动刷新页面的问题
    滴滴实习面试题
    CSS 日常积累
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/6537550.html
Copyright © 2011-2022 走看看