国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

??
自定義min版smarty模板引擎MinSmarty.class.php文件及用法,smarty模板引擎
? ??? ?? PHP ???? 自定義min版smarty模板引擎MinSmarty.class.php文件及用法,smarty模板引擎_PHP教程

自定義min版smarty模板引擎MinSmarty.class.php文件及用法,smarty模板引擎_PHP教程

Jul 12, 2016 am 08:50 AM
smarty ??? ?? ??? ??

自定義min版smarty模板引擎MinSmarty.class.php文件及用法,smarty模板引擎

本文實例講述了自定義的min版smarty模板引擎MinSmarty.class.php文件。分享給大家供大家參考,具體如下:

一、smarty的優(yōu)點

smarty是一個使用PHP寫出來的模板引擎,是目前業(yè)界最著名的PHP模板引擎之一。它分離了邏輯代碼和外在的內(nèi)容,提供了一種易于管理和使用的方法,用來將原本與HTML代碼混雜在一起PHP代碼邏輯分離。簡單的講,目的就是要使PHP程序員同前端人員分離,使程序員改變程序的邏輯內(nèi)容不會影響到前端人員的頁面設(shè)計,前端人員重新修改頁面不會影響到程序的程序邏輯,這在多人合作的項目中顯的尤為重要。

二、寫一個簡單的smarty模版類

具體代碼如下:

<&#63;php
 class MinSmarty{
 // 模版文件的路徑
 var $template_dir = "./templates/";
 // 模版文件被替換后的文件 命名格式為com_對應(yīng)的tpl.php
 var $complie_dir = "./templates_c/";
 // 存放變量值
 var $tpl_vars = array();
 // 這里使用兩個方法實現(xiàn)assign 和 display
 function assign($tpl_var,$var=NULL){
  if($tpl_var!=NULL){
  $this->tpl_vars[$tpl_var]=$var;
  }
 }
 // 這里編寫display方法的實現(xiàn)
 function display($tpl_file){
  // 讀取這個模版文件->替換可以運行的php文件(編譯后文件)
  $tpl_file_path=$this->template_dir.$tpl_file;  // 模版文件的路徑
  $complie_file_path=$this->complie_dir."com_".$tpl_file.".php";  //編譯后的文件路徑
  // 判斷文件是否存在
  if(!file_exists($tpl_file_path)){
  return false;
  }
  // 不讓每次執(zhí)行都生成編譯文件
  if(!file_exists($complie_file_path) || filemtime($tpl_file_path)>filemtime($complie_file_path)){
  $fp1_file_con=file_get_contents($tpl_file_path); // 獲取模版文件的全部內(nèi)容
  // 這里進(jìn)行正則替換把  模版文件中的代碼 {$title} 替換成 <&#63;php echo $this->tpl_vars['title'];&#63; >
  $pattern=array(
     '/\{\s*\$([a-zA-Z_][a-zA-Z0-9_]*)\s*\}/i'
  );
  $replace=array(
     '<&#63;php echo $this->tpl_vars["${1}"];&#63;>'
  );
  $new_str=preg_replace($pattern,$replace,$fp1_file_con);  // 替換后的內(nèi)容
  file_put_contents($complie_file_path,$new_str);  // 替換后的內(nèi)容生成一個php文件
  }
  // 引入編譯后的文件
  include_once("$complie_file_path");
 }
 }
&#63;>

下面的代碼是對該類的測試

intro.php代碼如下:

<&#63;php
  include_once("MySmarty.class.php");
  $title="這里是標(biāo)題";
  $content="這里是內(nèi)容111111";
  $MySmarty=new MySmarty();
  $MySmarty->assign("title",$title);
  $MySmarty->assign("content",$content);
  $MySmarty->display("intro.tpl");
&#63;>

模版如下:

intro.tpl:

<!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}</title>
</head>
<body>
{$content}
</body>
</html>

PS:這里推薦幾款本站的格式化/美化/轉(zhuǎn)換工具可以幫助你整理雜亂無章的代碼,相信大家在以后的開發(fā)中能夠用得上:

php代碼在線格式化美化工具:
http://tools.jb51.net/code/phpformat

JavaScript代碼美化/壓縮/格式化/加密工具:
http://tools.jb51.net/code/jscompress

在線XML格式化/壓縮工具:
http://tools.jb51.net/code/xmlformat

JSON代碼格式化美化工具:
http://tools.jb51.net/code/json

在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson

json代碼在線格式化/美化/壓縮/編輯/轉(zhuǎn)換工具:
http://tools.jb51.net/code/jsoncodeformat

sql代碼在線格式化美化工具:
http://tools.jb51.net/code/sqlcodeformat

更多關(guān)于Smarty相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《smarty模板入門基礎(chǔ)教程》、《PHP模板技術(shù)總結(jié)》、《PHP基于pdo操作數(shù)據(jù)庫技巧總結(jié)》、《PHP運算與運算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》

希望本文所述對大家基于smarty模板的PHP程序設(shè)計有所幫助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133123.htmlTechArticle自定義min版smarty模板引擎MinSmarty.class.php文件及用法,smarty模板引擎 本文實例講述了自定義的min版smarty模板引擎MinSmarty.class.php文件。分享給...
? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1601
29
PHP ????
1502
276
???
Netflix?? ??? ???? ??? ???? ?? Netflix?? ??? ???? ??? ???? ?? Feb 19, 2024 pm 06:33 PM

Netflix? ???? ??? ???? ???? ????? ??? ????. ???? ?? ???? ?? ??? ??? ??? ? ????. Netflix ??? ??? ?? ??? ??? ???? ??? ????? ? ??? ?? ?????. Netflix?? ??? ?? ???? ??? ???? ?? Netflix?? ??? ??? ???? ??? ???? ?? ????. ??? ????? Netflix ?? ????? ???? ? ??? ??? ? ????. ??, ????? Netflix ?? ????? ?? ??? ?? ??? ??? ?????. Chrome ????? ???? ? ????. ?? ????? ??? ? ?????? Netflix? ?? ??? ??????. ??? ??? ?? ???? ????

Python?? ? ?????? ??? ??? ???? ??? ?????? Python?? ? ?????? ??? ??? ???? ??? ?????? Sep 14, 2023 pm 02:37 PM

? ?????? ?? ?? ??? ???? ? ???? ????????. Venn ?????? ????? matplotlib? ?????. Matplotlib? Python?? ??? ??? ???? ??? ?? ????? ???? ??? ??? ????????. ?? ??? ???? ??? ??? ??? ?????. Matplotlib? ??? ???? ??? ??? ? ?? ??? ??? ?????. ? ??????? ? ?????? ??? ???? ? ?? ?? ?????. ??? ??? ??? ??? ????. ?? ??? ? ?? ? ?????? ???? ??? ??? ????. ?? ??? ?????? ???? ?? ??????. ?? ?? ??? ??? Python ??? ??? ? "venn2()" ??? ???? ?????.

Win11?? ?? ???? ??? ???? ?? Win11?? ?? ???? ??? ???? ?? Jun 30, 2023 pm 08:45 PM

Win11?? ?? ???? ??? ???? ??? ?????? ?? ??? win11 ????? ??? ??? ?? ???, ?? ??? ??? ????? ??? ???? ????. ?? ???? ?? ???? ????? ????? ???? ?? ???? ??? ???? ??? ?? ???? ???? ??? ??? ?? ????? ?? ??? ???????. ?? Win11?? ?? ???? ??? ?????. ??? ??? ??? ?????! Win11?? ?? ???? ??? ???? ??: 1. ??? ?? ?? ???? win ??? ???? ?? ???? ??? ?????. 2. ??? ?? ?? ??? ???? ?? ??? ?????. 3. ??? ?? ?? ??? ???? ??? ?????. 4. ?? ??? ???? ???? ??? ?????.

iOS 17? ??? iPhone? Apple Music?? ??????? ????? ??? ???? ?? iOS 17? ??? iPhone? Apple Music?? ??????? ????? ??? ???? ?? Jun 28, 2023 pm 12:14 PM

iPhone? iOS 17 ????? Apple Music? ? ?? ? ??? ??????. ???? ?? ???? ?? ???? ?? ??, CarPlay ?? ? ?? ???? ?? ?? ?? ?? ?????. ??? ??? ?? ? ??? Apple Music?? ??????? ???? ?????. ?? ?? ?? ?? ???? ??? ? ???, ?? ?? ??? ?? ? ?? ??? ?????. ??????? ???? ?? ??? ???? ??? ??? ? ???? ???? ???? ?? ??? ?????. ??? ? ??? ??? ??? ???? ??? iPhone?? ? ??? ???? ??? ??? ????. ??? ??? Apple Music? Crossfade? ????? ??? ???? ??

CakePHP?? ??? ?? ??? ??? ??? ??? ?????? CakePHP?? ??? ?? ??? ??? ??? ??? ?????? Jun 04, 2023 am 08:32 AM

CakePHP? ????? ?? ??? ??? ??? ???? ??? PHP ????????. ? ? ??? ??? ?????. ?? ?? ??? ???? ?? ???? ??? ??? ??? ? ?? ? ? ????. ????? CakePHP? ? ?? ???? ??? ?? ??? ????? ??? ??? ?? ??? ?? ??? ???? ? ?? ????. ? ????? CakePHP?? ??? ?? ??? ??? ??? ??? ?????. 1??: ??? ?? ??? ?? ??? ?? ?? ??? ?? ??? ?? ???? ???? ???. ??

Eclipse?? ?? ?? ? ??? ??? ???? ?? Eclipse?? ?? ?? ? ??? ??? ???? ?? Jan 28, 2024 am 10:01 AM

Eclipse?? ?? ?? ? ??? ??? ???? ??? ?????? ????? ???? ??? ?? Eclipse?? ??? ? ???? ??? ?? ? ?????. ??? ?? ?? ??? Eclipse? ??? ?? ???? ?? ??? ?? ??? ???? ??? ?? ??? ?? ??? ??? ?? ????. ? ????? Eclipse?? ?? ?? ? ??? ??? ???? ??? ???? ?? ?? ??? ?????. Eclipse ?? ?? Eclipse? ?? Enter? ?????.

CodeIgniter?? ??? ?? ????? ???? ?? CodeIgniter?? ??? ?? ????? ???? ?? Jul 29, 2023 am 10:53 AM

CodeIgniter?? ??? ?? ????? ???? ?? ??: ?? ? ???? ????? ???????? ??? ??? ???. ??? ????? ???? ??? ?? ?? ?? ?? ??? ???? ? ??? ? ????. ?? ???? PHP ?????? CodeIgniter? ???? ??? ?????. ? ???? CodeIgniter?? ??? ?? ????? ???? ??? ???? ??? ?? ??? ?????. ???? ??: ????? ??? ?????.

edius ??? ?? ?? ????? ?? ?? edius ??? ?? ?? ????? ?? ?? Mar 27, 2024 pm 06:50 PM

1. ?? ??? edius? ?? ?? ???????. ?? EDIUS ? ????? ?? ??????? ?? ??? ????? ?? ?? ??? ??? ???? ?? ?? ? ?????. 2. [??] ?? ?? ?? [?? ??? ??]? ????? ???? ?? ?? ?? ?? ?? ??? ????? ? ? ????. 3. [?? ???>? ????>??]? ?? ?? ?? ????? ??? ? ????. ??, ???? ?? ????? ??? ???? ?? ???? ?? ?????? ??? ?? ????. ?? ???? ?? ?????? ???? ? [?? > ? ???? > ?? ???? ?? > ?? ???]? ??? ? ?? [?? ???? ??] ????] ?? ?? ???? ??? ???? ??? ?????.

See all articles