smarty安裝及例子,smarty安裝例子_PHP教程

來源:互聯網
上載者:User

smarty安裝及例子,smarty安裝例子


環境:

smarty

1.在http://www.smarty.net/download下載最新smarty包,window選擇zips,linux下選擇tar.gz。以windows為例,下載後解壓,如f:\smarty。

2.把解壓出來的smarty目錄裡lib目錄拷貝到test裡,重新命名為smarty。在test目錄下,建立tpls目錄,在tpls目錄下,建立templates、templates_c、configs、cache目錄,這幾個目錄分別是模板目錄(必要),解析目錄(必要),配置目錄(可選),緩衝目錄(可選),

smarty的php代碼和這四個目錄是同一個級的,html代碼放在templates下。

分類樹如下

代碼部分:

1.在test/smarty下建立utf-8無bom格式的main.php,配置smarty的一些成員屬性。

 1 template_dir = SMARTY_ROOT."/templates/";//設定模板檔案的存放目錄 6 $tpl->compile_dir = SMARTY_ROOT."/templates_c/";//設定編譯檔案的存放目錄 7 $tpl->config_dir = SMARTY_ROOT."/configs/";//設定設定檔的存放目錄 8 $tpl->cache_dir = SMARTY_ROOT."/cache/";//設定快取檔案的存放目錄 9 $tpl->caching=1;//開啟緩衝10 $tpl->cache_lifetime=60*60*24;//有效時間為一天11 $tpl->left_delimiter = '[';//smarty語言的左右結束符12 $tpl->right_delimiter = ']';13 ?>

我們知道大括弧是smarty的預設定界符,但在和javascript、css等結合時可能會產生衝突,所以這裡我們設定為[和]。

2.在test/tpls/templates下面建立html.tpl模板檔案,就是在html中加入smarty變數。改模板相當於表現層。

html.tpl的代碼如下:

 1  2  3  4   5 [$title] 6   7   8   9 [$content]10  11 

3.在test目錄下建立smarty.php,該檔案相當於驅動層,給上面表現層的變數賦好值,然後顯示出來。

smarty.php的代碼如下:

1 assign("title","遲到");4     $tpl->assign("content","罰款500元!");5     $tpl->display("tpls/templates/html.tpl");6 ?>

4.在瀏覽器中運行smarty.php即可。

http://www.bkjia.com/PHPjc/1093865.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1093865.htmlTechArticlesmarty安裝及例子,smarty安裝例子 環境: smarty 1.在http://www.smarty.net/download下載最新smarty包,window選擇zips,linux下選擇tar.gz。以windows為例,下...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.