日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

PHP Smarty template for website

發布時間:2025/3/8 php 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 enginehttp://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.gz2. 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>.tpl4. 注釋:{* comments *}5. 賦值變量:$smarty->assign('name','Ned');6. 使用:{$name}7. 處理模板:$smarty->display('index.tpl');8. 打開debug模式:$smarty->debugging = true;9. 繼承class smarty,擴展功能:<?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 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. 繼承使用:<?phprequire('guestbook/setup.php');$smarty = new Smarty_GuestBook();$smarty->assign('name','Ned');$smarty->display('index.tpl');?>11. 解析JSON文件當配置文件,將數據放入smarty對象中,這樣就好配置了。

?

總結

以上是生活随笔為你收集整理的PHP Smarty template for website的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。