²ËÄñѧPHPÖ®SmartyÈëÃÅ

5年以前  |  阅读数:882 次  |  编程语言:PHP 

¸Õ¿ªÊ¼½Ó´¥Ä£°aeÒýÇaeµÄ PHP Ée¼Æʦ£¬Ìýµ½ Smarty ʱ£¬¶¼»a¾oµÃºÜÄÑ¡£Æaʵ±ÊÕßÒ²²»ÀýÍa£¬Åo¶¼²»¸ÒÅoһϡ£µ«ÊǺoÀ´ÔÚÆÊÎo XOOPS µÄ³ÌÐo¼Ü¹¹Ê±£¬¿ªÊ¼¢ÏÖ Smarty Æaʵ²¢²»ÄÑ¡£Ö»Òª½« Smarty »u´¡¹¦ÁºÃ£¬ÔÚÒ»°aÓ¦ÓÃÉϾÍÒѾ­Ïaµ±×a¹»ÁË¡£µ±È»»u´¡ÄÜ´oºÃ£¬ºoÃaeµÄ½ø½×Ó¦ÓÃÒ²¾Í²»ÓÃÅÂÁË¡£

ÕaƪÎÄÕµÄÖ÷ÒªÓÃÒa²¢ÇÒªÉiÈe̽ÌÖ Smarty µÄʹÓã¬ÕaÔڹٽʹÓÃ˵Ã÷Öж¼ÒѾ­Ð´µÃºÜÍeÕuÁË¡£±ÊÕß½oÔÚ´ËдÏÂÒ»Ð(C)×Ô¼ºÊ¹ÓÃÉϵÄÐĵã¬ÈÃÏeÒªÁ˽a Smarty È´²»µÃÆaÃŶøÈeµÄÅoÓÑ£¬¿ÉÒÔ´ÓÖеõ½Ò»Ð(C)Æoʾ¡£¾ÍÒoΪÕaƪÎÄÕµÄÄÚÈݲ»ÊÇ*dz£ÉiÈe£¬»aʹÓà Smarty µÄÅoÓÑÃÇ¿ÉÄÜ»a¾oµÃ¼oµ¥Á˵a¡£

Ä¿Ç°±¾ÎÄÒѾ­µÚÈý´ÎÐÞ¶(C)ÁË£¬±¾Ïe¶a¼ÓÒ»Ð(C)ÁϽøÀ´£»²»¹ý°­ÓÚʱ¼aµÄ¹Øϵ£¬ºÜ¶a Smarty µÄ½ø½×¼¼ÇɱÊÕß²¢Ã»ÓÐÑо¿µÃºÜ͸³¹£¬ËuÒÔÒ²²»¸ÒÄóoÀ´ÏÖÑÛ£¬µ«±ÊÕßÏaÐÅÕaƪÎÄÕÂÓ¦¸ÃÄܹ»Âu×a´o¶aÊýÏeѧϰ Smarty µÄ³oѧÕßÁË¡£µ±È»±¾ÎÄÓÐÃýÎoµÄµØ*½Ò²»¶Ó­¸aeÖª£¬±ÊÕß»aÔÚÏÂÒ»´ÎµÄÐÞ¶(C)ÖиuÕýµÄ¡£

Smarty½eÉÜ

ʲôÊÇÄ£°aeÒýÇae

²»ÖªµÀ´Óʲôʱºo¿ªÊ¼£¬ÓÐÈË¿ªÊ¼¶Ô HTML ÄÚǶÈe Server Script ¾oµÃ²»Ì«ÂuÒa¡£È»¶ø²»ÂÛÊÇ΢ÈiµÄ ASP »oÊÇ¿ªÅÔ´ÂeµÄ PHP£¬¶¼ÊÇÊoÓÚÄÚǶ Server Script µÄÍøÒ³ËÅþ¶ËÓiÑÔ¡£Òo´ËÒ²¾ÍÓÐÈËÏeµ½£¬Èç¹uÄܰѳÌÐoÓ¦ÓÃÂß¼­ (»o³ÆÉÌÒµÓ¦ÓÃÂß¼­) ÓeÍøÒ³³ÊÏÖ (Layout) Âß¼­*ÖÀeµÄ»°£¬ÊDz»ÊÇ»a±È½ÏºÃÄØ£¿

ÆaʵÕa¸oÎÊÌaÔç¾Í´aeÔÚÒѾ㬴ӽ»»¥Ê½ÍøÒ³¿ªÊ¼çÐÐʱ£¬²»ÂÛÊÇ ASP »oÊÇ PHP µÄʹÓÃÕ߶¼ÊÇÉi¼ae³ÌÐo¿ª¢ÕßÓeÊÓ¾oÉe¼ÆʦÁ½ÖÖÉi*Ý¡£¿ÉÊÇͨ³£ÕaÐ(C)ʹÓÃÕß²»ÊdzÌÐoÇ¿¾ÍÊÇÃÀ¹¤Ç¿£¬Èç¹uÒªÁ½Õßͬʱ¼ae¹Ë£¬ÄǿɵÃËÀµo²»ÉÙÄÔϸ°u...

ËuÒÔÄ£°aeÒýÇae¾ÍÓ¦Ô˶øÉuÀ²£¡Ä£°aeÒýÇaeµÄÄ¿µÄ£¬¾ÍÊÇÒª´iµ½ÉÏÊoÌaµ½µÄÂß¼­ÖÀeµÄ¹¦ÄÜ¡£ËuÄÜÈóÌÐo¿ª¢ÕßרעÓÚ×ÊÁϵĿØÖÆ»oÊǹ¦ÄܵĴi³É£»¶øÊÓ¾oÉe¼ÆʦÔo¿ÉרעÓÚÍøÒ³ÅÅ°ae£¬ÈÃÍøÒ³¿´ÆðÀ´¸u¾ßÓÐרҵ¸Ð£¡Òo´ËÄ£°aeÒýÇaeºÜÊʺϹ«Ë¾µÄÍøÕ¾¿ª¢ÍŶÓʹÓã¬Ê¹Ã¿¸oÈ˶¼ÄÜ¢»ÓÆaר³¤£¡

¾Í±ÊÕß½Ó´¥¹ýµÄÄ£°aeÒýÇaeÀ´Ëµ£¬ÒÀ×ÊÁϳÊÏֽʽ´o¸ÅֳɣºÐe´iÅa³ÌÐo´¦ÀiµÄÄ£°aeÒýÇaeºÍÍeÈ«ÓÉÄ£°ae±¾Éi×ÔÐоo¶¨µÄÄ£°aeÒýÇaeÁ½ÖÖÐÎʽ¡£

ÔÚÐe´iÅa³ÌÐo´¦ÀiµÄÄ£°aeÒýÇaeÖУ¬³ÌÐo¿ª¢Õß±ØÐeÒª¸ºÔð±aÁ¿µÄ³ÊÏÖÂß¼­£¬Ò²¾ÍÊÇ˵Ëu±ØÐe°Ñ±aÁ¿µÄÄÚÈÝÔÚÊa³oµ½Ä£°aeÇ°ÏÈ´¦ÀiºÃ£¬²ÅÄÜ×o assign µÄ¹¤×÷¡£»»¾a»°Ëµ£¬³ÌÐo¿ª¢Õß»¹ÊǵöaдһÐ(C)³ÌÐoÀ´¾o¶¨±aÁ¿³ÊÏÖµÄçò¡£¶øÍeÈ«ÓÉÄ£°ae±¾Éi×ÔÐоo¶¨µÄÄ£°aeÒýÇae£¬ËuÔÊÐi±aÁ¿Ö±½Ó assign µ½Ä£°aeÖУ¬ÈÃÊÓ¾oÉe¼ÆʦÔÚÉe¼ÆÄ£°aeʱÔÙ¾o¶¨±aÁ¿ÒªÈçºÎ³ÊÏÖ¡£Òo´ËËu¾Í¿ÉÄÜ»aÓÐÁiÒ»Ì×ÊoÓÚ×Ô¼ºµÄÄ£°ae³ÌÐoÓi¨ (Èç Smarty) £¬ÒÔ*½±a¿ØÖƱaÁ¿µÄ³ÊÏÖ¡£µ«ÕaÑuÒ»À´£¬ÊÓ¾oÉe¼ÆʦҲµÃѧϰÈçºÎʹÓÃÄ£°aeÓiÑÔ¡£

Ä£°aeÒýÇaeµÄÔË×÷Ô­Ài£¬Ê×ÏÈÎÒÃÇÏÈ¿´¿´ÒÔϵÄÔËÐÐͼ£º

Ò»°aµÄÄ£°aeÒýÇae (Èç PHPLib) ¶¼ÊÇÔÚ½¨Á¢Ä£°ae¶ÔÏoʱȡµÃÒª½aÎoµÄÄ£°ae£¬È»ºo°Ñ±aÁ¿Ì×Èeºo£¬Í¸¹ý parse() Õa¸o½¨À´½aÎoÄ£°ae£¬×iºoÔÙ½«ÍøÒ³Êa³o¡£

¶Ô Smarty µÄʹÓÃÕßÀ´Ëµ£¬³ÌÐoÀiÒ²²»ÐeÒª×oÈκΠparse µÄ¶¯×÷ÁË£¬ÕaÐ(C) Smarty ×Ô¶¯»a°iÎÒÃÇ×o¡£¶øÇÒÒѾ­±aÒe¹ýµÄÍøÒ³£¬Èç¹uÄ£°aeûÓбa¶¯µÄ»°£¬ Smarty ¾Í×Ô¶¯Ìø¹ý±aÒeµÄ¶¯×÷£¬Ö±½ÓÖ´ÐбaÒe¹ýµÄÍøÒ³£¬ÒÔ½ÚÊ¡±aÒeµÄʱ¼a¡£

ʹÓÃSmartyµÄÒ»Ð(C)¸ÅÄi

ÔÚÒ»°aÄ£°aeÒýÇaeÖУ¬ÎÒÃdz£¿´µ½ÇøÓoµÄ¹ÛÄi£¬ËuνÇø¿e´o¸Å¶¼»a³¤³ÉÕaÑu£º

ÇøÓoÄÚÈÝ

ÕaÐ(C)Çø¿e´o²¿Ý¶¼»aÔÚ PHP ³ÌÐoÖÐÒÔ if »o for, while À´¿ØÖÆËuÃǵÄÏÔʾ״̬£¬ËaȻģ°ae¿´ÆðÀ´¼o½a¶aÁË£¬µ«Ö»ÒªÒ»»»ÁËÏÔʾ½Ê½²»Í¬µÄÄ£°ae£¬ PHP ³ÌÐoÊƱØÒªÔÙ¸ÄÒ»´Î£¡

ÔÚ Smarty ÖУ¬Ò»ÇÐÒÔ±aÁ¿ÎªÖ÷£¬ËuÓеijÊÏÖÂß¼­¶¼ÈÃÄ£°ae×ÔÐпØÖÆ¡£ÒoΪ Smarty »aÓÐ×Ô¼ºµÄÄ£°aeÓiÑÔ£¬ËuÒÔ²»¹ÜÊÇÇø¿eÊÇñÒªÏÔʾ»¹ÊÇÒªÖظ´£¬¶¼ÊÇÓà Smarty µÄÄ£°aeÓi¨ (if, foreach, section) ´iÅa±aÁ¿ÄÚÈÝ×÷³ÊÏÖ¡£ÕaÑuÒ»À´¸Ð¾oÉϺÃÏoÄ£°ae±aµÃÓеa¸´ÔÓ£¬µ«ºÃ´¦ÊÇÖ»Òª¹ae»®µÃµ±£¬ PHP ³ÌÐoÒ»Ðж¼²»±Ø¸Ä¡£

ÓÉÉÏÃaeµÄ˵Ã÷£¬ÎÒÃÇ¿ÉÒÔÖªµÀʹÓÃSmarty ÒªÕÆÎÕÒ»¸oÔ­Ôo£º½«³ÌÐoÓ¦ÓÃÂß¼­ÓeÍøÒ³³ÊÏÖÂß¼­Ã÷ȵØÖÀe¡£¾ÍÊÇ˵ PHP ³ÌÐoÀi²»ÒªÓÐÌ«¶aµÄ HTML Âe¡£³ÌÐoÖÐÖ»Òª¾o¶¨ºÃÄÇÐ(C)±aÁ¿ÒªÈuµ½Ä£°aeÀi£¬ÈÃÄ£°ae×Ô¼º¾o¶¨¸ÃÈçºÎ³ÊÏÖÕaÐ(C)±aÁ¿ (ÉoÖÁ²»³oÏÖÒ²ÐÐ) ¡£

SmartyµÄ»u´¡

°²×°Smarty

Ê×ÏÈ£¬ÎÒÃÇÏȾo¶¨³ÌÐo*ÅÖõÄλÖá£

WindowsÏ¿ÉÄÜ»aÀaËÆÕaÑuµÄλÖ㺡¸ d:appservwebdemo ¡¹¡£

LinuxÏ¿ÉÄÜ»aÀaËÆÕaÑuµÄλÖ㺡¸ /home/jaceju/public_html/ ¡¹¡£

µ½SmartyµÄ¹Ù*½ÍøÕ¾ÏÂÔØ×iеÄSmartyÌ×¼þ£ºhttp://smarty.php.net¡£

½a¿ª Smarty 2.6.0 ºo£¬»a¿´µ½ºÜ¶aµµ°¸£¬ÆaÖÐÓиo libs ×ÊÁϼС£ÔÚ libs ÖÐÓ¦¸Ã»aÓÐ 3 ¸o class.php ™n + 1 ¸o debug.tpl + 1 ¸o plugin ×ÊÁϼР+ 1 ¸o core ×ÊÁϼС£È»ºoÖ±½Ó½« libs ¸´ÖƵ½ÄuµÄ³ÌÐoÖ÷×ÊÁϼÐÏ£¬ÔÙ¸uÃuΪ class ¾Í¿ÉÒÔÁË¡£¾ÍÕaÑu£¿Ã»´i£¡ÕaÖÖ°²×°*¨±È½Ï¼oµ¥£¬ÊʺÏÒ»°aûÓÐ×Ô¼ºÖ÷»uµÄʹÓÃÕß¡£

ÖÁÓÚ Smarty ¹Ù½ÊÖ²aÖÐΪʲôҪ½eÉÜÒ»Ð(C)±È½Ï¸´Ôӵݲװ½Ê½ÄØ£¿»u±¾ÉÏÒÀÕÕ¹Ù½µÄ½Ê½°²×°£¬¿ÉÒÔÖ»ÔÚÖ÷»u°²×°Ò»´Î£¬È»ºoÌa¹(C)¸ø¸ÃÖ÷»uÏÂËuÓÐÉe¼ÆÕß¿ª¢²»Í¬³ÌÐoʱֱ½ÓÒýÓ㬶ø²»»aÖظ´°²×°Ì«¶aµÄ Smarty ¸´±¾¡£¶ø±ÊÕßËuÌa¹(C)µÄ½Ê½ÔoÊÇÊʺÏÒª°Ñ³ÌÐo´ø¹ýÀ´ÒƹýÈ¥µÄ³ÌÐo¿ª¢ÕßʹÓã¬ÕaÑu²»ÓóÄÕÖ÷»uÓÐûÓа²×° Smarty ¡£

³ÌÐoµÄ×ÊÁϼÐÉe¶¨

ÒÔ±ÊÕßÔÚWindows°²×°AppservΪÀý£¬³ÌÐoµÄÖ÷×ÊÁϼÐÊÇ¡¸d:appservwebdemo¡¹¡£°²×°ºÃSmartyºo£¬ÎÒÃÇÔÚÖ÷×ÊÁϼÐÏÂÔÙ½¨Á¢ÕaÑuµÄ×ÊÁϼУº

ÔÚ Linux µ×Ï£¬Çe¼ÇµÃ½« templates_c µÄȨÏÞ±a¸uΪ 777 ¡£Windows ÏÂÔo½«ÆaÖ»¶ÁÈ¡Ïu¡£

µÚÒ»¸oÓÃSmartyдµÄС³ÌÐo

ÎÒÃÇÏÈÉe¶¨ Smarty µÄ¾¶£¬Çe½«ÒÔÏÂÕa¸oµµ°¸ÃuÃuΪ main.php £¬²¢ÅÖõ½Ö÷×ÊÁϼÐÏ£º

main.php:

<?php
include "class/Smarty.class.php";
define(@#SITE_ROOT@#, @#d:/appserv/web/demo@#); // ×iºoûÓÐбÏß
$tpl = new Smarty();
$tpl->template_dir =
SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = SITE_ROOT . "/configs/";
$tpl->cache_dir =
SITE_ROOT . "/cache/";
$tpl->left_delimiter = @#<{@#;
$tpl->right_delimiter = @#}>@#;
?>

ÕÕÉÏÃae½Ê½Ée¶¨µÄÓÃÒaÔÚÓÚ£¬³ÌÐoÈç¹uÒªÒÆÖ²µ½ÆaËuµØ½£¬Ö»Òª¸Ä __SITE_ROOT ¾Í¿ÉÒÔÀ²¡£ (ÕaÀiÊDzο¼ XOOPS µÄ )

Smarty µÄÄ£°ae¾¶Ée¶¨ºÃºo£¬³ÌÐo»aÒÀÕÕÕa¸o¾¶À´×¥ËuÓÐÄ£°aeµÄÏa¶ÔλÖà (¶ÀýÖÐÊÇ @#d:/appserv/web/demo/templates/@# ) ¡£È»ºoÎÒÃÇÓà display() Õa¸o Smarty ½*¨À´ÏÔʾÎÒÃǵÄÄ£°ae¡£

½ÓÏÂÀ´ÎÒÃÇÔÚ templates ×ÊÁϼÐÏÂÅÖÃÒ»¸o test.htm£º(À(C)Õ¹Ãu½Ðʲô¶¼ÎÞËuν£¬µ«±aÓÚÊÓ¾oÉe¼Æʦ¿ª¢£¬±ÊÕ߶¼»¹ÊÇÒÔ .htm ΪÖ÷¡£)

templates/test.htm:

<{$title}> <{$content}>

ÏÖÔÚÎÒÃÇÒª½«ÉÏÃaeµÄÄ£°aeÏÔʾ³oÀ´£¬²¢½«ÍøÒ³±eÌa ($title) ÓeÄÚÈÝ ($content) ¸u»»£¬Çe½«ÒÔϵµ°¸ÄÚÈÝÃuÃuΪ test.php £¬²¢*ÅÖÃÔÚÖ÷×ÊÁϼÐÏ£º

test.php:

<?php
require "main.php";
$tpl->assign("title", "²aÊÔÓõÄÍøÒ³±eÌa");
$tpl->assign("content", "²aÊÔÓõÄÍøÒ³ÄÚÈÝ");
// ÉÏÃaeÁ½ÐÐÒ²¿ÉÒÔÓÃÕaÐдuÌae
// $tpl->assign(array("title" => "²aÊÔÓõÄÍøÒ³±eÌa", "content" => "²aÊÔÓõÄÍøÒ³ÄÚÈÝ"));
$tpl->display(@#test.htm@#);
?>

Çe´o¿ªa¯ÀÀÆ÷£¬ÊaÈe http://localhost/demo/test.php ÊÔÊÔ¿´(ÒÀÄuµÄ»¾³¾o¶¨ÍøÖ)£¬Ó¦¸Ã»a¿´µ½ÒÔϵĻ­Ãae£º

ÔÙµ½ templates_c µ×Ï£¬ÎÒÃÇ»a¿´µ½Ò»¸oÆae¹ÖµÄ×ÊÁϼР(%%179) £¬ÔÙµaÑ¡ÏÂÈ¥Ò²ÊÇÒ»¸oÆae¹ÖµÄ×ÊÁϼР(%%1798044067) £¬¶øÆaÖÐÓÐÒ»¸oµµ°¸£º

templates_c/%%179/%%1798044067/test.htm.php:

<?php / Smarty version 2.6.0, created on 2003-12-15 22:19:45 compiled from test.htm / ?>

<?php echo $this->_tpl_vars[@#title@#]; ?> _tpl_vars[@#content@#]; ?>

û´i£¬Õa¾ÍÊÇ Smarty ±aÒe¹ýµÄµµ°¸¡£Ëu½«ÎÒÃÇÔÚÄ£°aeÖеıaÁ¿×ª»»³ÉÁË PHP µÄÓi*¨À´Ö´ÐУ¬Ï´ÎÔÙ¶ÁȡͬÑuµÄÄÚÈÝʱ£¬ Smarty ¾Í»aÖ±½ÓץȡÕa¸oµµ°¸À´Ö´ÐÐÁË¡£

×iºoÎÒÃÇÕuÀiÒ»ÏÂÕu¸o Smarty ³ÌÐo׫д²½Öe£º

Step 1. ¼ÓÔØ Smarty Ä£°aeÒýÇae¡£

Step 2. ½¨Á¢ Smarty ¶ÔÏo¡£

Step 3. Ée¶¨ Smarty ¶ÔÏoµÄ²ÎÊý¡£

Step 4. ÔÚ³ÌÐoÖд¦Ài±aÁ¿ºo£¬ÔÙÓà Smarty µÄ assign ½¨½«±aÁ¿ÖÃÈeÄ£°aeÀi¡£

Step 5. ÀuÓà Smarty µÄ display ½¨½«ÍøÒ³Ða³o¡£

ÈçºÎ°²ÅÅÄaµÄ³ÌÐo¼Ü¹¹

ÉÏÃaeÎÒÃÇ¿´µ½³ýÁË Smarty ËuÐeÒªµÄ×ÊÁϼÐÍa (class ¡¢ configs ¡¢ templates ¡¢ templates_c) £¬»¹ÓÐÁ½¸o×ÊÁϼУº includes ¡¢ modules ¡£ÆaʵÕaÊDZÊÕßģ XOOPS µÄ¼Ü¹¹Ëu½¨Á¢³oÀ´µÄ£¬ÒoΪ XOOPS ÊDZÊÕßËu½Ó´¥µ½µÄ³ÌÐoÖУ¬ÉÙÊýʹÓà Smarty Ä£°aeÒýÇaeµÄ¼ÜÕ¾³ÌÐo¡£ËuνÎ÷¹ÏÙË´o±ß£¬±ÊÕßÕaÑuµÄ³ÌÐo¼Ü¹¹ËaûÓÐ XOOPS µÄ°ÙÖ֮һǿ£¬µ«ÖÁÉÙ¸øÈË¿´Ê±»¹ÓÐ XOOPS ³ÅÑu¡£

includes Õa¸o×ÊÁϼÐÖ÷ÒªÊÇÓÃÀ´*ÅÖÃÒ»Ð(C) function ¡¢ sql ™n£¬ÕaÑuÔÚ main.php ¾Í¿ÉÒÔ½«ËuÃÇÒýÈeÁË£¬ÈçÏ£º

main.php:

<?php
include "class/Smarty.class.php";
define(@#SITE_ROOT@#, @#d:/appserv/web/demo@#); // ×iºoûÓÐбÏß
// ÒÔ main.php µÄλÖÃΪ»u×¼
require_once "includes/functions.php";
require_once "includes/include.php";
$tpl = new Smarty();
$tpl->template_dir =
SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = SITE_ROOT . "/configs/";
$tpl->cache_dir =
SITE_ROOT . "/cache/";
$tpl->left_delimiter = @#<{@#;
$tpl->right_delimiter = @#}>@#;
?>

modules Õa¸o×ÊÁϼÐÔoÊÇÓÃÀ´*ÅÖóÌÐoÄ£¿eµÄ£¬Èç´ËÒ»À´±a²»»a°Ñ³ÌÐo¶ªµÃµ½´¦¶¼ÊÇ£¬ÕuÌa¼Ü¹¹Ò»Ä¿ÁËÈ»¡£

ÉÏÃaeÎÒÃÇÒ²Ìaµ½ main.php £¬ÕaÊÇÕu¸o³ÌÐoµÄÖ÷ÒªºËÐÄ£¬²»ÂÛÊdz£Êý¶¨Òa¡¢Ía²¿³ÌÐo¼ÓÔØ¡¢¹²Ïi±aÁ¿½¨Á¢µÈ£¬¶¼ÊÇÔÚÕaÀi¿ªÊ¼µÄ¡£ËuÒÔÖ®ºoµÄÄ£¿e¶¼Ö»Òª½«Õa¸oµµ°¸°uº¬½øÀ´¾Í¿ÉÒÔÀ²¡£Òo´ËÔÚ³ÌÐoÁ÷³Ì¹ae»®ÆÚ¼a£¬¾Í±ØÐeºÃºÃ¹¹Ë¼ main.php ÖÐÓ¦¸ÃÒªÅÄÇÐ(C)¶«Î÷£»µ±È»ÀuÓà include »o require Ö¸Ái£¬°Ñÿ¸o»½ÚÇa³þ*ÖÀeÊÇÔٺò»¹ýÁË¡£

ÔÚÉϽÚÌaµ½µÄ Smarty ³ÌÐo 5 ²½Öe£¬ main.php ¾Í»a°iÎÒÃÇÏȽ«Ç° 3 ¸o²½Öe×oºÃ£¬ºoÃaeµÄÄ£¿e³ÌÐoÖ»Òª×oºoÃaeÁ½¸o²½Öe¾Í¿ÉÒÔÁË¡£

´Ó±aÁ¿¿ªÊ¼

ÈçºÎʹÓñaÁ¿

´ÓÉÏÒ»Õ¶ÀýÖУ¬ÎÒÃÇ¿ÉÒÔÇa³þµØ¿´µ½ÎÒÃÇÀuÓà <{ ¼° }> ÕaÁ½¸o±eʾuºÅ½«±aÁ¿°uÆðÀ´¡£Ô¤ÉeµÄ±eʾuºÅΪ { ¼° } £¬µ«ÎªÁËÖÐÎijaÂe¼° javascript µÄ¹Øϵ£¬Òo´Ë±ÊÕß»¹ÊÇģ XOOPS £¬½«±eʾuºÅ»»µo¡£±aÁ¿µÄÃuÃu½Ê½ºÍ PHP µÄ±aÁ¿ÃuÃu½Ê½ÊÇһģһÑuµÄ£¬Ç°ÃaeÒ²Óиo $ ×ֺŠ(ÕaºÍÒ»°aµÄÄ£°aeÒýÇae²»Í¬)¡£±eʾuºÅ¾ÍÓеaÏñÊÇ PHP ÖеÄ
<?php ¼° ?>

(ÊÂʵÉÏËuÃǵÄÈ»a±»Ìae»»³ÉÕa¸o) £¬ËuÒÔÒÔϵÄÄ£°ae±aÁ¿Ð´¨¶¼ÊÇ¿ÉÐеģº

  1. <{$var}>

  2. <{ $var }>

  3. <{$var

}>
ÔÚ Smarty Ài£¬±aÁ¿Ô¤ÉeÊÇÈ«ÓoµÄ£¬Ò²¾ÍÊÇ˵ÄaÖ»ÒªÖ¸¶¨Ò»´Î¾ÍºÃÁË¡£Ö¸¶¨Á½´ÎÒÔÉϵĻ°£¬±aÁ¿ÄÚÈÝ»aÒÔ×iºoÖ¸¶¨µÄΪÖ÷¡£¾ÍËaÎÒÃÇÔÚÖ÷Ä£°aeÖмÓÔØÁËÍa²¿µÄ×ÓÄ£°ae£¬×ÓÄ£°aeÖÐͬÑuµÄ±aÁ¿Ò»ÑuÒ²»a±»Ìae´u£¬ÕaÑuÎÒÃǾͲ»ÓÃÔÙÕe¶Ô×ÓÄ£°aeÔÙ×oÒ»´Î½aÎoµÄ¶¯×÷¡£

¶øÔÚ PHP ³ÌÐoÖУ¬ÎÒÃÇÓà Smarty µÄ assign À´½«±aÁ¿ÖÃŵ½Ä£°aeÖС£ assign µÄÓè¹Ù½ÊÖ²aÖÐÒѾ­Ð´µÃºÜ¶aÁË£¬Óè¾ÍÈçͬÉÏÒ»½ÚµÄ*¶ÀýËuʾ¡£²»¹ýÔÚÖظ´Çø¿eʱ£¬ÎÒÃǾͱØÐe½«±aÁ¿×oÒ»Ð(C)Êֽźo£¬²ÅÄܽ«±aÁ¿ assign µ½Ä£°aeÖУ¬ÕaÔÚÏÂÒ»ÕÂÔÙÌa¡£

ÐÞÊÎÄaµÄ±aÁ¿

ÉÏÃaeÎÒÃÇÌaµ½ Smarty ±aÁ¿³ÊÏÖµÄçòÊÇÓÉÄ£°ae×ÔÐоo¶¨µÄ£¬ËuÒÔ Smarty Ìa¹(C)ÁËÐi¶aÐÞÊαaÁ¿µÄº¯Ê½¡£Ê¹ÓõĽ*¨ÈçÏ£º

<{±aÁ¿|ÐÞÊκ¯Ê½}>

<{±aÁ¿|ÐÞÊκ¯Ê½:"²ÎÊý(DZØÒª£¬ÊÓº¯Ê½¶ø¶¨)"}>
¶ÀýÈçÏ£º

<{$var|nl2br}>

<{$var|string_format:"%02d"}>
ºÃ£¬ÄÇΪʲôҪÈÃÄ£°ae×ÔÐоo¶¨±aÁ¿³ÊÏÖµÄçò£¿ÏÈ¿´¿´µ×Ï嵀 HTML £¬ÕaÊÇij¸o¹ºÎi³µ½aÕʵIJ¿Ý»­Ãae¡£

×ܽð¶i£º21,000 Ôª
Ò»°aÄ£°aeÒýÇaeµÄÄ£°ae¿ÉÄÜ»aÕaÑuд£º

×ܽð¶i£º{format_total} Ôª
ËuÃÇµÄ PHP ³ÌÐoÖÐÒªÕaÑuд£º

<?php
$total = 21000;
$tpl->assign("total", $total);
$tpl->assign("format_total", number_format($total));
?>

¶ø Smarty µÄÄ£°ae¾Í¿ÉÒÔÕaÑuд£º (number_format ÐÞÊκ¯Ê½Çeµ½Smarty ¹Ù*½ÍøÒ³ÏÂÔØ)

×ܽð¶i£º<{$total|number_format:""}> Ôª
Smarty µÄ PHP ³ÌÐoÖÐÖ»ÒªÕaÑuд£º

<?php
$total = 21000;
$tpl->assign("total", $total);
?>

ËuÒÔÔÚ Smarty ÖÐÎÒÃÇÖ»ÒªÖ¸¶¨Ò»´Î±aÁ¿£¬Ê£ÏµĽ»¸øÄ£°ae×ÔÐоo¶¨¼´¿É¡£ÕaÑuÁ˽aÁËÂð£¿Õa¾ÍÊÇÈÃÄ£°ae×ÔÐоo¶¨±aÁ¿³ÊÏÖ*çòµÄºÃ´¦£¡

¿ØÖÆÄ£°aeµÄÄÚÈÝ

Öظ´µÄÇø¿e

ÔÚ Smarty Ñu°aÖУ¬ÎÒÃÇÒªÖظ´Ò»¸oÇø¿eÓÐÁ½ÖÖ*½Ê½£º foreach ¼° section ¡£¶øÔÚ³ÌÐoÖÐÎÒÃÇÔoÒª assign Ò»¸oÊý×e£¬Õa¸oÊý×eÖпÉÒÔ°uº¬Êý×eÊý×e¡£¾ÍÏñÏÂÃaeÕa¸oÀý×Ó£º

Ê×ÏÈÎÒÃÇÀ´¿´ PHP ³ÌÐoÊÇÈçºÎдµÄ£º

test2.php:

<?php
require "main.php";
$array1 = array(1 => "Æ»¹u", 2 => "²¤ÂÜ", 3 => "Ïa½¶", 4 => "°ÅÀÖ");
$tpl->assign("array1", $array1);
$array2 = array(
array("index1" => "data1-1", "index2" => "data1-2", "index3" => "data1-3"),
array("index1" => "data2-1", "index2" => "data2-2", "index3" => "data2-3"),
array("index1" => "data3-1", "index2" => "data3-2", "index3" => "data3-3"),
array("index1" => "data4-1", "index2" => "data4-2", "index3" => "data4-3"),
array("index1" => "data5-1", "index2" => "data5-2", "index3" => "data5-3"));
$tpl->assign("array2", $array2);
$tpl->display("test2.htm");
?>

¶øÄ£°aeµÄд*¨ÈçÏ£º

templates/test2.htm:

²aÊÔÖظ´Çø¿e
    
ÀuÓà foreach À´³ÊÏÖ array1    
<{foreach item=item1 from=$array1}>    
<{$item1}>    
<{/foreach}>    
ÀuÓà section À´³ÊÏÖ array1    
<{section name=sec1 loop=$array1}>    
<{$array1[sec1]}>    
<{/section}>    
ÀuÓà foreach À´³ÊÏÖ array2    
<{foreach item=index2 from=$array2}>    
<{foreach key=key2 item=item2 from=$index2}>    
<{$key2}>: <{$item2}>    
<{/foreach}>    
<{/foreach}>    
ÀuÓà section À´³ÊÏÖ array1    
<{section name=sec2 loop=$array2}>    
index1: <{$array2[sec2].index1}>    
index2: <{$array2[sec2].index2}>    
index3: <{$array2[sec2].index3}>    
<{/section}>    

Ö´ÐÐÉÏÀýºo£¬ÎÒÃÇ*¢ÏÖ²»¹ÜÊÇ foreach »o section Á½¸oÖ´Ðнa¹uÊÇÒ»ÑuµÄ¡£ÄÇôÁ½Õßµ½µ×Óкβ»Í¬ÄØ£¿

µÚÒ»¸o²i±ðºÜÃ÷ÏÔ£¬¾ÍÊÇforeach ÒªÒÔ³²×´´¦ÀiµÄ½Ê½À´³ÊÏÖÎÒÃÇËu assign µÄÁ½²aÊý×e±aÁ¿£¬¶ø section ÔoÒÔ¡¸Ö÷Êý×e[Ñ­»Ãu³Æ].×ÓÊý×eË÷Òý¡¹¼´¿É½«Õu¸oÊý×e³ÊÏÖ³oÀ´¡£ÓÉ´Ë¿ÉÖª£¬ Smarty ÔÚÄ£°aeÖÐµÄ foreach ºÍ PHP ÖÐµÄ foreach ÊÇÒ»ÑuµÄ£»¶ø section ÔoÊÇ Smarty ΪÁË´¦ÀiÈçÉÏÁеÄÊý×e±aÁ¿Ëu¢Õ¹³oÀ´µÄÐðÊo¡£µ±È» section µÄ¹¦ÄÜ»¹²»Ö»Èç´Ë£¬³ýÁËÏÂÒ»½ÚËu̸µ½µÄ³²×´×ÊÁϳÊÏÖÍa£¬¹Ù½ÊÖ²aÖÐÒ²Ìa¹(C)Á˺ü¸¸o section µÄÓ¦ÓÃ*¶Àý¡£

²»¹ýҪעÒaµÄÊÇ£¬¶ª¸ø section µÄÊý×eË÷Òý±ØÐeÊÇ´Ó 0 ¿ªÊ¼µÄÕýÕuÊý£¬¼´ 0, 1, 2, 3, ...¡£Èç¹uÄuµÄÊý×eË÷Òý²»ÊÇ´Ó 0 ¿ªÊ¼µÄÕýÕuÊý£¬ÄÇô¾ÍµÃ¸ÄÓà foreach À´³ÊÏÖÄuµÄ×ÊÁÏ¡£Äu¿ÉÒԲο¼¹Ù½ÌÖÂÛÇøÖеĴËƪÌÖÂÛ£¬ÆaÖÐ̽ÌÖÁË section ºÍ foreach µÄÓè¡£

³²×´×ÊÁϵijÊÏÖ

Ä£°aeÒýÇaeÀi×iÁiÈËÉËÄÔ½iµÄ´o¸Å¾ÍÊdz²×´×ÊÁϵijÊÏÖ°É£¬Ði¶aÖøÃuµÄÄ£°aeÒýÇae¶¼»aÌØÒaÇ¿µ÷Õaµa£¬²»¹ýÕa¶Ô Smarty À´ËµÈ´ÊÇС¶u¿Æ¡£

×i³£¼uµ½µÄ³²×´×ÊÁÏ£¬¾ÍËaÂÛ×Z³ÌÐoÖеÄÌÖÂÛÖ÷ÌaÇø°É¡£¼ÙÉeÒª³ÊÏֵĽa¹uÈçÏ£º

¹«¸aeÇø

Õ¾Îñ¹«¸ae

ÎÄѧרÇø

ºÃÊe½eÉÜ

ÆaeÎĹ²ÉÍ

¼ÆËa»uרÇø

Ó²¼þÍaΧ

Èi¼þÌÖÂÛ

³ÌÐoÖÐÎÒÃÇÏÈÒÔ¾²Ì¬×ÊÁÏΪÀý£º

test3.php:

<?php
require "main.php";
$forum = array(
array("category_id" => 1, "category_name" => "¹«¸aeÇø",
"topic" => array(
array("topic_id" => 1, "topic_name" => "Õ¾Îñ¹«¸ae")
)
),
array("category_id" => 2, "category_name" => "ÎÄѧרÇø",
"topic" => array(
array("topic_id" => 2, "topic_name" => "ºÃÊe½eÉÜ"),
array("topic_id" => 3, "topic_name" => "ÆaeÎĹ²ÉÍ")
)
),
array("category_id" => 3, "category_name" => "¼ÆËa»uרÇø",
"topic" => array(
array("topic_id" => 4, "topic_name" => "Ó²¼þÍaΧ"),
array("topic_id" => 5, "topic_name" => "Èi¼þÌÖÂÛ")
)
)
);
$tpl->assign("forum", $forum);
$tpl->display("test3.htm");
?>

Ä£°aeµÄд*¨ÈçÏ£º

templates/test3.htm:

³²×´Ñ­»*²aÊÔ <{section name=sec1 loop=$forum}> <{section name=sec2 loop=$forum[sec1].topic}> <{/section}> <{/section}>
<{$forum[sec1].category_name}>
<{$forum[sec1].topic[sec2].topic_name}>

Ö´ÐеĽa¹u¾ÍÏñ±ÊÕß¾ÙµÄÀý×ÓÒ»Ñu¡£

Òo´ËÄØ£¬ÔÚ³ÌÐoÖÐÎÒÃÇÖ»ÒªÏe°i¨°ÑËuÒªÖظ´ÖµÒ»²aÒ»²aµÄÈuµ½Êý×eÖУ¬ÔÙÀuÓà <{µÚÒ»²aÊý×e[Ñ­»1].µÚ¶þ²aÊý×e[Ñ­»2].µÚÈý²aÊý×e[Ñ­»3]. ... .Êý×eË÷Òý}> ÕaÑuµÄ½Ê½À´ÏÔʾÿһ¸o³²×´Ñ­»ÖеÄÖµ¡£ÖÁÓÚÓÃʲô½¨ÄØ£¿ÏÂÒ»½ÚʹÓÃÊý¾Ý¿aʱÎÒÃÇÔÙÌa¡£

ת»»Êý¾Ý¿aÖеÄ×ÊÁÏ

ÉÏÃaeÌaµ½ÈçºÎÏÔʾ³²×´Ñ­»£¬¶øʵ¼ÊÉÏÓ¦ÓÃʱÎÒÃǵÄ×ÊÁÏ¿ÉÄÜÊÇ´ÓÊý¾Ý¿aÖÐץȡ³oÀ´µÄ£¬ËuÒÔÎÒÃǾ͵ÃÏe°i¨°ÑÊý¾Ý¿aµÄ×ÊÁϱa³ÉÉÏÊoµÄ¶aÖØÊý×eµÄÐÎʽ¡£ÕaÀi±ÊÕßÓÃÒ»¸o DB Àa±ðÀ´×¥È¡Êý¾Ý¿aÖеÄ×ÊÁÏ£¬Äu¿ÉÒÔ×ÔÐÐÓÃÄuϲ»¶µÄ½¨¡£

ÎÒÃÇÖ»ÐÞ¸Ä PHP ³ÌÐo£¬Ä£°ae»¹ÊÇÉÏÃaeÄǸo (Õa¾ÍÊÇÄ£°aeÒýÇaeµÄºÃ´¦~)£¬ÆaÖÐ $db Õa¸o¶ÔÏo¼ÙÉeÒѾ­ÔÚ main.php Öн¨Á¢ºÃÁË£¬¶øÇÒ×¥³oÀ´µÄ×ÊÁϾÍÊÇÉÏÃaeµÄÀý×Ó¡£

test3.php:

<?php
require "main.php";
// ÏȽ¨Á¢µÚÒ»²aÊý×e
$category = array();
$db->setSQL($SQL1, @#CATEGORY@#);
if (!$db->query(@#CATEGORY@#)) die($db->error());
// ץȡµÚÒ»²aÑ­»µÄ×ÊÁÏ
while ($item_category = $db->fetchAssoc(@#CATEGORY@#))
{
// ½¨Á¢µÚ¶þ²aÊý×e
$topic = array();
$db->setSQL(sprintf($SQL2, $item_category[@#category_id@#]), @#TOPIC@#);
if (!$db->query(@#TOPIC@#)) die($db->error());
// ץȡµÚ¶þ²aÑ­»
µÄ×ÊÁÏ
while ($item_topic = $db->fetchAssoc(@#TOPIC@#))
{
// °ÑץȡµÄÊý¾ÝÍÆÈeµÚ¶þ²aÊý×eÖÐ
array_push($topic, $item_topic);
}
// °ÑµÚ¶þ²aÊý×eÖ¸¶¨ÎªµÚÒ»²aÊý×eËuץȡµÄÊý¾ÝÖеÄÒ»¸o³ÉÔ±
$item_category[@#topic@#] = $topic;
// °ÑµÚÒ»²aÊý¾ÝÍÆÈeµÚÒ»²aÊý×eÖÐ
array_push($category, $item_category);
}
$tpl->assign("forum", $category);
$tpl->display("test3.htm");
?>

ÔÚÊý¾Ý¿aץȡһ±Ê×ÊÁϺo£¬ÎÒÃǵõ½µÄÊÇÒ»¸o°uº¬¸Ã±ÊÊý¾ÝµÄÊý×e¡£Í¸¹ý while ÐðÊo¼° array_push º¯Ê½£¬ÎÒÃǽ«Êý¾Ý¿aÖеÄ×ÊÁÏÒ»±ÊÒ»±ÊÈuµ½Êý×eÀi¡£Èç¹uÄuÖ»Óõ½µ¥²aÑ­»£¬¾Í°ÑµÚ¶þ²aÑ­» (ºiÉ«µÄ²¿*Ý) È¥µo¼´¿É¡£

¾o¶¨ÄÚÈÝÊÇ*ñÏÔʾ

Òª¾o¶¨ÊÇñÏÔʾÄÚÈÝ£¬ÎÒÃÇ¿ÉÒÔʹÓà if Õa¸oÓi¨À´×oÑ¡Ôñ¡£ÀýÈçÈç¹uʹÓÃÕßÒѾ­µÇÈeµÄ»°£¬ÎÒÃǵÄÄ£°ae¾Í¿ÉÒÔÕaÑuд£º

<{if $is_login == true}>
ÏÔʾʹÓÃÕß²Ù×÷Ñ¡µ¥
<{else}>
ÏÔʾÊaÈeÕʺźÍÃÜÂeµÄ´°Ìa
<{/if}>

ҪעÒaµÄÊÇ£¬¡¸==¡¹ºÅÁ½±ßÒ»¶¨Òª¸÷ÁoÖÁÉÙÒ»¸o¿Õ¸ñu£¬ñÔo Smarty »aÎÞ*¨½aÎo¡£

if Ói¨Ò»°aµÄÓ¦ÓÿÉÒÔ²ÎÕչٽʹÓÃ˵Ã÷£¬ËuÒÔ±ÊÕßÔÚÕaÀi¾Í²»Ïe¼Ó½eÉÜÁË¡£²»¹ý±ÊÕß*¢ÏÖÁËÒ»¸oÓÐȤµÄÓ¦Ó㺳£³£»a¿´µ½³ÌÐoÀiÒª²uÉuÕaÑuµÄÒ»¸o±i¸ñ£º (Êý×Ö´u±iµÄÊÇ×ÊÁϼ¯µÄ˳Ðo)

1 2

3 4

5 6

7 8

Õa¸o±ÊÕß³Æ֮Ϊ¡¸ºaÏoÖظ´±i¸ñ¡¹¡£ËuµÄÌØÉ«ºÍ´«Í³µÄ×ÝÏoÖظ´²»Í¬£¬Ç°¼¸½ÚÎÒÃÇ¿´µ½µÄÖظ´±i¸ñ¶¼ÊÇ´ÓÉ϶øÏ£¬Ò»ÁÐÖ»ÓÐÒ»±Ê×ÊÁÏ¡£¶øºaÏoÖظ´±i¸ñÔo¿ÉÒÔºaÏoµØÔÚÒ»ÁÐÖвuÉu n ±Ê×ÊÁϺo£¬ÔÙ»»ÏÂÒ»ÁУ¬Ö±µ½Õu¸oÑ­»½aÊø¡£Òª´iµ½ÕaÑuµÄ¹¦ÄÜ£¬×i¼oµ¥µÄ½Ê½Ö»ÐeÒª section ºÍ if ´iÅa¼´¿É¡£

ÎÒÃÇÀ´¿´¿´ÏÂÃaeÕa¸oÀý×Ó£º

test4.php:

<?php
require "main.php";
$my_array = array(
array("value" => "0"),
array("value" => "1"),
array("value" => "2"),
array("value" => "3"),
array("value" => "4"),
array("value" => "5"),
array("value" => "6"),
array("value" => "7"),
array("value" => "8"),
array("value" => "9"));
$tpl->assign("my_array", $my_array);
$tpl->display(@#test4.htm@#);
?>

Ä£°aeµÄд*¨ÈçÏ£º

templates/test4.htm:

ºaÏoÖظ´±i¸ñ²aÊÔ <{section name=sec1 loop=$my_array}> <{if $smarty.section.sec1.rownum is div by 2}> <{/if}> <{/section}>
<{$my_array[sec1].value}>

ÖصaÔÚÓÚ $smarty.section.sec1.rownum Õa¸o Smarty ±aÁ¿£¬ÔÚ section Ñ­»ÖÐÕa¸o±aÁ¿»aÈ¡µÃ´Ó 1 ¿ªÊ¼µÄË÷ÒýÖµ£¬ËuÒÔµ± rownum Äܱ» 2 ³ý¾¡Ê±£¬¾ÍÊa³o ʹ±i¸ñ»»ÁÐ (×¢Òa£¡ÊÇ ÔÚÇ°Ãae ÔÚºoÃae) ¡£Òo´ËÊý×Ö 2 ¾ÍÊÇÎÒÃÇÔÚÒ»ÁÐÖÐÏeÒª³ÊÏÖµÄ×ÊÁϱÊÊý¡£¸÷λ¿ÉÒÔÓÉ´ËÈ¥±a»¯ÆaËu²»Í¬µÄ³ÊÏֽʽ¡£

¼ÓÔØÍa²¿ÄÚÈÝ

ÎÒÃÇ¿ÉÒÔÔÚÄ£°aeÄÚ¼ÓÔØ PHP ³ÌÐo´uÂe»oÊÇÁiÒ»¸o×ÓÄ£°ae£¬Ö±ðÊÇʹÓà include_php ¼° include ÕaÁ½¸o Smarty Ä£°aeÓi¨£» include_php ±ÊÕß½ÏÉÙÓã¬Ê¹Óýʽ¿ÉÒÔ²eѯ¹Ù½ÊÖ²a£¬ÕaÀi²»ÔÙÐðÊo¡£

ÔÚʹÓà include ʱ£¬ÎÒÃÇ¿ÉÒÔÔ¤ÏȼÓÔØ×ÓÄ£°ae£¬»oÊǶ¯Ì¬¼ÓÔØ×ÓÄ£°ae¡£Ô¤ÏȼÓÔØͨ³£Ê¹ÓÃÔÚÓй²Í¬µÄÎļþ±eÍ*¼°°aeȨÐu¸ae£»¶ø¶¯Ì¬¼ÓÔØÔo¿ÉÒÔÓÃÔÚͳһµÄ¿o¼ÜÒ³£¬¶ø½øÒ»²½´iµ½Èç Winamp °a¿É»» Skin ¡£µ±È»ÕaÁ½ÖÖÎÒÃÇÒ²¿ÉÒÔ»iÓã¬ÊÓ×´¿o¶ø¶¨¡£

ÎÒÃÇÀ´¿´¿´ÏÂÃaeÕa¸oÀý×Ó£º

test5.php:

<?php
require "main.php";
$tpl->assign("title", "Include ²aÊÔ");
$tpl->assign("content", "ÕaÊÇÄ£°ae 2 ÖеıaÁ¿");
$tpl->assign("dyn_page", "test5_3.htm");
$tpl->display(@#test5_1.htm@#);
?>

Ä£°ae 1 µÄд*¨ÈçÏ£º

templates/test5_1.htm:

<{$title}> <{include file="test5_2.htm"}>
<{include file=$dyn_page}> <{include file="test5_4.htm" custom_var="×Ô¶(C)±aÁ¿µÄÄÚÈÝ"}>

Ä£°ae 2 µÄд*¨ÈçÏ£º

templates/test5_2.htm:

<{$content}>
Ä£°ae 3 µÄд*¨ÈçÏ£º

templates/test5_3.htm:

ÕaÊÇÄ£°ae 3 µÄÄÚÈÝ
Ä£°ae 4 µÄд*¨ÈçÏ£º

templates/test5_4.htm:

<{$custom_var}>
ÕaÀi×¢Òa¼¸¸oÖصa£º1. Ä£°aeµÄλÖö¼ÊÇÒÔÏÈÇ°¶¨ÒaµÄ template_dir Ϊ»u×¼£»2. ËuÓÐ include ½øÀ´µÄ×ÓÄ£°aeÖУ¬Æa±aÁ¿Ò²»a±»½aÒe¡££»3. include ÖпÉÒÔÓḱaÁ¿Ãu³Æ=±aÁ¿ÄÚÈÝ¡¹À´Ö¸¶¨Òýº¬½øÀ´µÄÄ£°aeÖÐËu°uº¬µÄ±aÁ¿£¬ÈçͬÉÏÃaeÄ£°ae 4 µÄ×o*¨¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例