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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

smarty基础

發布時間:2024/4/17 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 smarty基础 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

smarty基礎原理

一、html模板頁面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> </head><body> <div>{$title}</div> <div>{$content}</div> </body> </html>

二、PHP后臺代碼

<?php //連接數據庫,獲得具體數據//1.引入迷你smart require ("minismart.class.php"); //2實例化Smarty對象 $smarty=new minismart(); //將字符串信息設置為模板引擎類的屬性信息 $smarty->assign("title","qqq"); $smarty->assign("content","aa");//3調用compile方法,同時傳遞ceshi.html模板文件參數 //在該方法中把ceshi.html內部標記替換為php標記 $smarty->compile("ceshi.html");

三、模板引擎

<?php //模板引擎類 class minismart { //給該類聲明屬性,用于儲存外部的變量信息public $tpl_var=array();//把外部變量設置成內部變量的一部分function assign($k,$v){$this->tpl_var[$k]=$v;}//"編譯模板文件({}標記替換為php標記)"function compile ($tpl) //compile編譯{ //獲得模板文件內部具體內容$cont= file_get_contents($tpl);//file_get_contents()獲取內容//替換 { ---> <?php echo $this->tpl_var["$cont=str_replace("{\$","<?php echo \$this->tpl_var[\"",$cont);//替換 } --->"]; ? >$cont=str_replace("}","\"]; ?>",$cont);//把生成好的編譯內容(php + html 混編內容)放入一個文件里面file_put_contents("./shili.html.php",$cont);//引入混編文件include ("./shili.html.php");}}

四、混編代碼頁面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> </head><body> <div><?php echo $this->tpl_var["title"]; ?></div> <div><?php echo $this->tpl_var["content"]; ?></div> </body> </html>

?

轉載于:https://www.cnblogs.com/m-m-g-y0416/p/5700081.html

總結

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

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