PHP Smarty template for website

來源:互聯網
上載者:User

標籤:book   flow   ace   span   https   isp   blog   注釋   com   

/****************************************************************************** *                        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. 處理模板:        $smarty->display(‘index.tpl‘);    7. 開啟debug模式:        $smarty->debugging = true;    8. 繼承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‘);           }        }        ?>    9. 繼承使用:        <?php        require(‘guestbook/setup.php‘);        $smarty = new Smarty_GuestBook();        $smarty->assign(‘name‘,‘Ned‘);        $smarty->display(‘index.tpl‘);        ?>    10. 解析JSON檔案當設定檔,將資料放入smarty對象中,這樣就好配置了。

 

PHP Smarty template for website

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.