smarty 3.0中国語マニュアルドキュメントAPIおよび使用マニュアル


1、  Smarty3.0

 、   smarty?

smarty     PHP      PHP    ,              ,    ,        PHP        ,                           ,                     ,                。

 、smarty  :

1.   :  smarty                ,                   。

2.    :  smarty                     PHP  ,        PHP HTML     ,          WEB            ,            (            )

3.     :smarty         ,           HTML          HTML , 
   smarty cache   true ,  smarty   cachetime      WEB            HTML    ,            HTML  。

4.     :smarty       。              。

5.        if/elseif/else/endif。                           。

 、     smarty   :

1.          。       ,            ,        smarty          。

2.    。                       ,  smarty   php       。

  smarty     ,www.smarty.net/download.php。  Smarty 3.0rc4,        rc  (Release.Candidate.        , beta    ,        ,       !)。  tar.gz zip     linux windows  。

    tar –zxvf Smarty 3.0rc4.tar.gz

   ,demo        。Libs     。

/libs/Smarty.class.php   #   

/libs/sysplugins/  #  plugin

/libs /plugins/   #  plugin,     

/demo/cahce/   #      

/demo/configs /   #           

/demo/templates/   #      

/demo/templates_c/    #           

       smarty            demo        (       web     ),               ,       smarty          。Smarty3.0  php5.0  。

2、  Smarty3.0
       ,  index.php。 
 templates       index.tpl(               ,     tpl,php,html,        ,                。    apache httpd.conf    ,      .tpl  。   templats           。)

[Index.php]

require_once("../../Smarty-3.0rc4/libs/Smarty.class.php");

$smarty = new smarty();

$smarty->assign(‘name’,'   ’);

$smarty->display(‘templates/index.tpl ‘);

[Index.tpl]   :

<html><body>

<span>  , {$name}</span>

</body></html>

Smarty          php  ->    (      )-> php  。。。 
        php          。  smarty          html,         。

3、Smarty3.0  
3.1 smarty    

smarty php   ,         (  php),      ,              (  php),             。                (          ),         (         ,          ),                   ,         ,      。        ,        ,              。  php              。           ,           。 
Smarty              :

1、             (    ):                ,              ,        。

$smarty->setCompile_check(false)     
#   true,false                         ,       。

$smarty->getCompile_check()    #           

 2、         (    ):         。

$smarty->setForce_compile(true)  #   false,true         (      ,       )

$smarty->getForce_compile()    #           

3.2    

      ,    html   smarty        。      “{ }“,   js css   。 
      。 3.0           , {  $abc  } Smarty2      , 
  3.0      ,    {$abc},            javascript css。

$smarty->left_delimiter = "<{";   #    ,2.0  ,3.0  

$smarty->right_delimiter = "}>";   #    ,2.0  ,3.0  

  :         , 3.0          ,  <{ $abc }>,  。

3.3   

{* smarty *           *}

          “<{}>“, <{* smarty *           *}>。          。

3.4       

   {include file="         "}

Head.tpl

<span>      ,   ,{$name}</span><hr />

Index.tpl      

{include file="head.tpl"}

    :

      ,   ,   。

  ,   !

          ,     html、php(    smarty  php     ,     include_php  )。           。

Head.tpl

<span>{$nr},   ,{$name}</span><hr />

Index.tpl

{include file="head.tpl" nr=”      ”}

      。

3.5       

                 ,        ,      。         configs    ,     。

My.conf

gv = "my.conf      "   #      ,      ,     

#  $sections,   ,      

[color]   #      

fontcolor = "red"   #  $sections,   red,        [color]    

[size]  #      

fontsize = "12px"   #  $sections,   size,        [size]    

           ,        ,         。

    :$smarty->configLoad($config_file, $sections = null)

     :{config_load file="       " section=”       (  )”scope=“      (  )“}

          ,                   global,             (smarty         )。

      ,     。     config_load scope        local (   ,           ), parent(       )    global(   smarty          ,               )

            

{#    #}  {$smarty.config.    }

【    】

$smarty->getConfigVariable($variable)    #        ,      parent   global

$smarty->getConfigVars($varname = null)   #        ,      。 
           parent   global

$smarty->clearConfig($varname = null)  #                   

$smarty->setConfig_overwrite(false)   #       ,              (        ) 
          。  ,           。           ,    cycle  。     getConfig_overwrite  。

$smarty->setConfig_booleanize(true);   #   true  ,       on/true/yes/1   off/false/no/0          , false      (        ,    )。      getConfig_booleanize  。

3.6     

Smary            、  、  、    。

$smarty->template_dir = "./templates";    #      ,2.0    ,3.0      

$smarty->compile_dir = "./templates_c";   #      ,2.0    ,3.0      

$smarty->config_dir = ‘./configs/’;        #      ,2.0    ,3.0      

$smarty->cache_dir = ‘./cache/’;         #      ,2.0    ,3.0      

Smary 3.0         。                。

$smarty->getCacheDir();   #          

$smarty->getTemplateDir();   #             

$smarty->getConfigDir(); #           

$smarty->getCompileDir(); #          

$smarty->getPluginsDir()   #            

              

$smarty->setTemplateDir("../smarty1/templates/");    #        , 
                  ,        。

$smarty->setCompileDir("../smarty1/templates_c/");   #        

$smarty->setConfigDir("../smarty1/configs/");        #        

$smarty->setCacheDir("../smarty1/cache/");         #        

$smarty->addTemplateDir("templates");     #                    , 
    ,            ,           ,            。

$smarty->addPluginsDir(‘myplugins’);   #          ,   set       ,    

【    】

$smarty->utility->compileAllTemplates($extention = ‘.tpl’, $force_compile = false,  $time_limit = 0, $max_errors = null)   #                 ,    。

$smarty->utility->clearCompiledTemplate($resource_name = null,  $compile_id = null, $exp_time = null)  

#                       。

$smarty-> setDefault_template_handler_func($fucname)    
#                       ,       ,        。

4、Smarty     
4.1   

             。

1、   php        。

$smarty->assign(‘name’,'   ’);    #  php     

<span>  , {$name}</span> #        

2、            。

$smarty->configLoad(“configs/my.conf”)  #  php         ,         

<span style="color:{#fontcolor#}; font-size:{#fontsize#};">  {#gv#}</span><br />  #        

3、          。

{assign var="name" value="   " nocache=”false”scope=”global”}    
#         ,            ,          。

{$name="   "}    #       ,          ,    ,3.0   。

{assign var=foo value=[1,2,3]}     #        

{assign var=foo value=['y'=>'yellow','b'=>'blue']}    #      

{assign var=foo value=[1,[9,8],3]}  #        

{$foo[]=1}    #      $foo     

<span>  , {$name}</span> #        

【    】

$smarty->getVariable($variable, $_ptr = null, $search_parents = true,  
$error_enable = true) #    ,             

$smarty->getTemplateVars($varname = null, $_ptr = null, $search_parents = true)    
#    ,                (       scope   global  parent), 
           3.4

4.2 Smarty    

Smarty            ,           。      php       。

1、      (Request variables)

$smarty.get.         #    get            。

$smarty.post.        #    post            。

$smarty.cookies.   #    cookie       。

$smarty.server.SERVER_NAME   #  server   ,phpinfo() $_SERVER    

$smarty.env.PATH   #         ,phpinfo() $_ENV    

$smarty.session.   #  session       

$smarty.request.   #    post、get、cookie       。

2、      

{$smarty.now} #  unix     ,          ,  4.2.4,      {time()}

3、      

{$smarty.const._MY_CONST_VAL}   #  php                

4、{$smarty.capture} 

  4.4.1

5、      

{$smarty.config.    }   #      ,    #    #   

6、{$smarty.section}, {$smarty.foreach}

  4.4.3 4.4.4

7、{$smarty.template}   #         

4.3     

4.2.1  

{$name =   }   ,{$name=”        ”}   #       ,        , 
        。          。

{$name =    }   ,{$name = 1+2+$foo['bar']}  #$foo['bar']   1,     4

{$foo['bar']=1}    #          

{$foo['bar']['blar']=1}   #            

{$foo = array(1,2,3,4,5)}   #  php      $foo,   。

4.2.2  

          {$var},       {#configvar#}

          {$array[1][1]},     {$array.1.1}

     {$object->method1($x)},      ,{$object->method1($x)->method2($y)}

           

{"   ,  $name<br />"}   #Smarty              , 
          、  、   。

{"   ,  `$name[$obj->a]`<br />"}    #   []、  .      -> ,        `    。

4.2.3     

 php  ,             ,smarty        。

$foo         #       

$foo_{$bar}   #        

$foo_{$x+$y}  #           

$foo_{$bar}_buh_{$blar}   #         

4.2.4     

                。

{$var|capitalize}   #       

{$var|count_characters:false}   #         ,false      。 
                       

{$var| cat:var2} # var2   var,          。

{$var| count_paragraphs} #          , “
“ {$var| count_sentences} # , {$var| count_words} # {$var| date_format :"%H:%M:%S" } # , chm {$var| default:"no title" } # , {$var| escape:url} # , chm {$var| indent:10:"*"} # , html , chm {$var| lower} # {$var| nl2br } # “
“ ”<br />“ {$var| regex_replace:"/[\r\t
]/":" "} # {$var| replace:"Garden":"Vineyard"} # {$var| spacify:"^^"} # , {$var|string_format:"%d"} # , printf {$var| strip: "*"} # , {$var| strip_tags} # html , < > , < > {$var| truncate:30:"…":true} # , chm {$var| upper} # {$var| wordwrap:30:"
":true} # , chm 。 {$articleTitle|lower|spacify|truncate:30:". . ."} $smarty->getDefault_modifiers() # $smarty->setDefault_modifiers(array(‘spacify:"^^"’,'capitalize’) # , array {name} # name , 6.7.4 6.8.4 4.2.5 ( ) 4.4 4.4.1 capture capture , . {capture name="foo"} {/capture} $foo 。 , , $smarty.capture. 。 {capture name="bottom"} {include file="bottom.tpl" nr=" "} {/Capture} {if true } # , {$smarty.capture.bottom} {/if} 4.4.2 config_load 3.4 4.4.3 foreach,foreachelse foreach ( ) {foreach name= item= key= from= } #2.0 ,3.0 {foreachelse} From (0 ) 。 {/foreach} : {foreach name=for1 item=num from=$foo} {$smarty.foreach.for1.index+1} :{$num}<br /> {if is_array($num)} {foreach name=for2 item=num2 key=key2 from=$num} {$str|cat:$smarty.foreach.for2.index+1|cat:" :"|cat:$num2|cat:" key "|cat:$key2|indent:1:"."}<br /> {/foreach} {/if} {foreachelse} {$smarty.foreach.for1.index+1} : !<br /> {/foreach} foreach $smarty.foreach.foreachname.index #( ) , , -1 $smarty.foreach.foreachname. iteration #( ) $smarty.foreach.foreachname.first #( ) , true $smarty.foreach.foreachname.last #( ) , true $smarty.foreach.foreachname.total #( ) foreach 3.0 , php, 。 {foreach $myarray as $var}…{/foreach} foreach , $var@key # , 012, 。 $var@iteration # , $var@index # , , -1, $var@total # $var@first # , true $var@last # , true 4.4.4 section,sectionelse section , 。 3.0 , for ,for php 。 ,section 。 {section name= loop= ( ) start= (0) step= (1) max= show= (true)} #2.0 ,3.0 {sectionelse} loop (0 ) 。 {/section } : {section name=sec1 loop=$foo step=1 start=0 show=true} {$smarty.section.sec1.index+1} :{$foo[sec1]} {$smarty.section.sec1.iteration}<br /> {if is_array($foo[sec1])} {section name=sec2 loop=$foo[sec1] step=1 start=0 show=true} {$smarty.section.sec2.index+1} :{$foo[sec1][sec2]} {$smarty.section.sec2.iteration}<br /> {/section} {/if} {sectionelse} {$smarty.section.sec1.index} : !<br /> {/section} Section foreach 。 4.4.5 include {include file=" " var=” ”assign=” ”} assign , , assign , , 。 capture。 4.4.6 include_php {include_php file=" " once=” (true)”assign=” ”} php , , 。 assign , , assign , , 。 4.4.7 insert Insert 。 。 insert 。 {insert name=” ” script=” ”var….=” ” assign=” ”} Insert , “smarty_insert_ ($params,&$smarty)”, insert , , 。 : {insert name="maxnum" script="s2.php" x=12 y=13 assign=nn} # ,script {foreach $nn as $n} {$n} {/foreach} function smarty_insert_maxnum($arr) # { return $arr['x']>$arr['y']?$arr['x']:$arr['y']; } assign , , assign , , 。 Insert , , 6.8.5 4.4.8 if,elseif,else {if $name eq "Fred"} Welcome Sir. {elseif $name eq "Wilma"} Welcome Ma’am. {else} Welcome, whatever you are. {/if} 。 “==、>=” , ”eq、ne” , 。 4.4.9 ldelim,rdelim , smarty 。 。 4.4.10 literal Literal , 。 js、css 。 {literal}{/literal} , , 。 4.4.11 strip Smarty {strip}{/strip} 。 4.4.12 php php php 。 {php} , $smarty->setAllow_php_tag(true) # php $smarty->getAllow_php_tag() # {php} 4.4.13 for,while 3.0 。 php, {for $x=0, $y=count($foo); $x<$y; $x++} …. {/for} {for $x=0 to count($foo)-1 step 1} , for 。 。 $x@iteration # $x@total # $x@first # $x@last # {while true}….{/while} While 。 4.5 4.5.1 assign {assign var="name" value=" " nocache=”false”scope=”global”} # $smarty->assign($tpl_var, $value = null, $nocache = false, $scope = SMARTY_LOCAL_SCOPE) # php nocache ( )。 scope , global、parent、local 【 】 $smarty->assignGlobal($varname, $value = null, $nocache = false) # $smarty->assignByRef($tpl_var, &$value, $nocache = false, $scope = SMARTY_LOCAL_SCOPE) # , , , 。 $smarty->clearAssign($tpl_var) # $smarty->clearAllAssign() # 4.5.2 append 3.0 , , , 。 $smarty->append($tpl_var, $value = null, $merge = false, $nocache = false, $scope = SMARTY_LOCAL_SCOPE) #php {append var="name" value="2"} # : $smarty->assign(‘nh’, ‘var1); # , var1 $smarty->append(‘nh’,'var2′); # , 。nh 。 {$nh[0]} # $merge, , , 。 【 】 $smarty->appendByRef($tpl_var, &$value, $merge = false) # ,$merge 。 4.5.3 counter 。 {counter} , {counter} 。 {counter start= (1) skip= (1) direction= / (up/down) print= (true) assign= } counter start assign , , counter 。 assign , , assign , , 。 4.5.4 cycle 。 {cycle} , {cycle} 。 {cycle name= values= print= (true) advance= (true) delimiter= (,) assign= } 4.5.5 debug , 。 , {debug} fetch(), debug 。 display()。 {debug output= (javascript/html) } # ,, js 。 $smarty->getDebugging() # , false $smarty->setDebugging(true) # 。 $smarty->getDebug_tpl() # tpl , 。 $smarty->setDebug_tpl(‘new_debug.tpl’) # 4.5.6 eval eval 。 , 。 4.5.7 fetch fetch 、HTTP FTP 。 "http://" , 。 "ftp://" , ftp 。 {fetch file="/export/httpd/www.domain.com/docs/navbar.js"} {fetch file="ftp://user:[email protected]/path/to/currentheadlines.txt"} {fetch file="http://www.myweather.com/68502/" assign="weather"} {if $weather ne ""}<b>{$weather}</b>{/if} , html , 【 】 $smarty->fetch($template, $cache_id = null, $compile_id = null, $parent = null) # , , id, 3, “3^ ”, id 。 $output = $smarty->fetch("index.tpl"); // do something with $output here// echo $output; 4.5.8 math math . {math equation= [var…]= format= assign= } 4.5.9 popup_init,popup javascript 。 {popup_init src="/javascripts/overlib.js"} #popup_init js , 。 {popup text=” ”} # , , chm 4.5.10 textformat textformat 。 , 。 , , 。 {textformat [ ….]} {/textformat} 4.5.11 html_checkboxes checkboxes( ) 。 {html_checkboxes name= (checkbox) values= ouput= selected= , values options= (value+output) separator= label= <label> (true)} {assign var=cb_values value=[1,2,3,4,5,6] scope="global"} {assign var=cb_content value=[' ',' ',' ',' ',' ',' '] scope="global"} {assign var=cb value=['1'=>' ','3'=>' ','2'=>' ','4'=>' ','5'=>' ','6'=>' '] scope="global"} {assign var=cb_selected value=[1,2]} {html_checkboxes name="checkbox" values=$cb_values output=$cb_content selected=$cb_selected separator="|"} {html_checkboxes name="checkbox" options=$cb selected=$cb_selected separator="|"} 4.5.12 html_image , html , img id name {html_image file= border= height= width= alt=alt href= url} 4.5.13 html_options {html_options name= values= ouput= selected= options= (value+output) } , name , <select></select> 。 selected , 。 4.5.14 html_radios {html_radios name= (radio) values= ouput= selected= options= (value+output) separator= } 4.5.15 html_select_date,html_select_time,html_table , , 。 。 4.5.16 mailto {mailto address= cc= bcc= subject= text= encode= (javascript/hex)} , 。 4.6 3.0 , 。 {function name= [var…]= } # 。。 {/function} {call name= [var…]= } # , { [var…]= } # 5、 5.1 smarty 。 。 display fetch 。 , , 3.4。 $smarty->getCaching() # $smarty->setCaching(true) # $smarty->isCached($template, $cache_id = null, $compile_id = null) # ( / id/ id) ( , ) $smarty->setcache_lifetime(60); # $smarty->getcache_lifetime(); # , 3600(1 ) $smarty->display/fetch( , =null, =null, =null) display/fetch 。 , , , 。 $smarty->cache->clearAll($exp_time = null, $type = null) # , $exp_time , $smarty->cache->clear($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) # , $smarty->cache->clear($template_name) # template_name $smarty->cache->clear(null, null, $compile_id) # id compile_id $smarty->cache->clear(null, $cache_id = null, $compile_id) # id cache_id id compile_id 5.2 , , , 、 。 。 1、nocache $smarty->assign/append($tpl_var, $value = null, $nocache = true …) # nocache = true, {$foo nocache=true} # , {time() nocache} # ,nocache nocache=true nocache, , , 。 2、insert Insert , insert , , 4.4.7 3、{nocache}…..{/nocache} 。 , , , 。insert 。 5.3 , 。 index?id=1 index?id=2 , , cache_id。 :Index.php if(empty($_GET['id']))$_GET['id'] = null; $smarty->assign(‘name’,' 1′.$_GET['id']); $smarty->display(‘templates/t3.tpl’,$_GET['id'],$_GET['id']); id , id (index.php), ( ), id=1 (index.php?id=1), (1^ )。 5.4 , index.php?id=2&sid=3, 。 id sid , , index.php?id=23, 。 , 。 if(empty($_GET['id']))$_GET['id'] = null; if(empty($_GET['sid']))$_GET['sid'] = null; $smarty->assign(‘name’,' 1′.$_GET['id']); $smarty->display(‘templates/t3.tpl’,$_GET['id'].’|’.$_GET['sid']); # "|" , cache_id. "^", , "^" php , , 。 5.5 smarty 、 , mysql 、 。 $smarty->Cache_handler_func=‘ ’ 3.0 。 6、smarty 6.1 6.1.1 pre 。 , 。 。 , 。 : $smarty->register->preFilter(‘mypre’); # $smarty->unregister->preFilter (‘mypre’); # function mypre($tpl_source, &$smarty) # PHP , , , { return "mypre<br />".$tpl_source; } smarty libs/plugins , 。 php ,prefilter. .php( prefilter.mypre.php) # php function smarty_prefilter_mypre($source, $smarty) # smarty , { return "mypre_plus<br />".$source; } $smarty->autoload_filters = array(‘pre’=>array(‘mypre’)); # php $smarty->autoload_filters = array() # , $smarty->register->preFilter(‘mypre’); # , , $smarty->register->preFilter(‘mypre1′); $smarty->autoload_filters = array(‘pre’=>array(‘mypre’,'mypre1′)); # , , 。 6.1.2 post (PHP ), 。 , 。 。 : $smarty->register->postFilter(‘mypre’); # $smarty->unregister->postFilter (‘mypre’); # function mypost($tpl_source, &$smarty) # php , , , { return "mypost<br />".$tpl_source; } smarty libs/plugins , 。 php ,postfilter. .php( postfilter.mypost.php) # php function smarty_postfilter_mypost($source, $smarty) # smarty , { return "mypost_plus<br />".$source; } $smarty->autoload_filters = array(‘post’=>array(‘mypost’)); # php $smarty->autoload_filters = array(‘post’=>array()) # , $smarty->register->postFilter(‘mypost’); # , , $smarty->register->postFilter(‘mypost1′); $smarty->autoload_filters = array(‘post’=>array(‘mypost’,'mypost1′)); # , , 。 6.1.3 output , , 。 pre post , pre post ( php )。 output , , 。 pre post , include file, 。 output ( ) : $smarty->register->outputFilter(‘myoutput’); # $smarty->unregister->outputFilter (‘mypre’); # function myoutput($tpl_source, &$smarty) # php , , , { return "myoutput<br />".$tpl_source; } smarty libs/plugins , 。 php ,outputfilter. .php( outputfilter.myoutput.php) # php function smarty_outputfilter_myoutput($source, $smarty) # smarty , { return "myoutput_plus<br />".$source; } $smarty->autoload_filters = array(‘output’=>array(‘myoutput’)); # php $smarty->autoload_filters['output'] = array() # , $smarty->register->outputFilter(‘myoutput’); # , , $smarty->register->outputFilter(‘myoutput1′); $smarty->autoload_filters = array(‘output’=>array(‘myoutput’,'myoutput1′)); # , , 。 6.2 6.2.1 trigger_error php trigger_error Void trigger_error(string error_msg, [int level]) #int level , ,E_USER_NOTICE, E_USER_WARNING 。set_error_handler() 。 $smarty->trigger_error($error_msg, $error_type = E_USER_WARNING) # PHP , $smarty 6.2.2 $smarty->setExceptionHandler(handlerfuncname) # , smarty , trigger_error。set_error_handler() php , smarty 。 function handlerfuncname($errstr) { echo $errstr; } 6.3 3.0 。 $smarty , , , 。 $smarty->createData($parent = null) # , , 。 : $mydata = $smarty->createData(); # , $mydata1 = $smarty->createData($mydata); # , $mydata $mydata->assignByRef(‘assign_obj’,&$han); $mydata->assign(‘name’,'abcd’); $mydata1-> assign(‘name’,'bcds’); #mydata1 mydata , , $smarty->display(‘templates/t4.tpl’,null,null,$mydata1); # , , 。 , 6.4 6.4 3.0 。 $smarty , , ( ) 。 $smarty->createTemplate($template, $cache_id = null, $compile_id = null, $parent = null) # , , id id。 : $mytemplate = $smarty->createTemplate(‘templates/t4.tpl’); # , , $smarty $mytemplate1 = $smarty->createTemplate(‘templates/t4.tpl’,null,null,$mydata); # , mydata,mydata 。 $mytemplate->assignByRef(‘assign_obj’,&$han); # $mytemplate->assign(‘name’,'abcd’); $mytemplate->display(); # 。 include , 。 , {assign} {$foo=…} 。 6.5 , {block} … {/block} , 。 : Parent.tpl —————————————————– <html> <body> {block name=’top’} Parent.tpl <br />{/block}<hr /> {block name=’middle’} Parent.tpl <br />{/block}<hr /> {block name=’buttom’} Parent.tpl <br />{/block} </body> </html> child.tpl {extends file=’parent.tpl’} # {block name=’top’}{$smarty.block.parent}{"`$smarty.template` "} {/block} #child top 。 。 extends , block , 。 , {$smarty.block.parent} block 。 , {block} … {/block} , , , 。 {block} append prepend 6.6 ( ) 6.7 , , 6.8 6.7.1 SMARTY PHP 。 。 , 。 $smarty->register->templateObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) # ,allowed 。 $smarty->register->templateObject(‘reg_obj’,$han,array(‘show’,'show1′)); {reg_obj->show var=2 var1=3} # , ! , insert $smarty->unregister->templateObject($object_name) # , , , , 。 , 。 $mysmarty->assignByRef(‘assign_obj’,&$han); # , , {$assign_obj-> } # 。 6.7.2 $smarty->register->block($block_tag, $block_impl, $cacheable = true, $cache_attr = array()) / 。 。 ; array(&$object, $method) , &$object , $method ; array(&$ class, $method) , $class ,$method 。 $cacheable, , , true。 $cacheattr, $cacheale false, , , 。 : $hanobj = new han(); $smarty->setcaching(true); $smarty->register->block(‘hhh’, array(&$hanobj,’myf’),false,array(‘fn’)); # class han{ 。。。。。。 public function myf($params,$content,&$smarty,&$repeat){ # return " ".$params['fn'].$params['un']." !<br />\r
".$content; } } {hhh fn=$name un=$name1} # , , fn aaaaaaa {time()} {/hhh} $smarty->unregister->block($block_tag) # 6.7.3 $smarty->register->compilerFunction($compiler_tag, $compiler_impl, $cacheable = true) # , $smarty->register->templateFunction($function_tag, $function_impl, $cacheable = true, $cache_attr = array()) # ,3.0 , , 。 ; array(&$object, $method) , &$object , $method ; array(&$ class, $method) , $class ,$method 。 : $hanobj = new han(); $smarty->setcaching(true); $smarty->register->templateFunction(‘hhh’, array(&$hanobj,’myf’),false,array(‘fn’)); class han{ ……………. public function myf($params,&$smarty,&$repeat){ # 3 return time()." ".$params['fn'].$params['un']." !<br />\r
"; } } {hhh fn=$name un=$name1} # , , fn $smarty->unregister->compilerFunction($compiler_tag) # $smarty->unregister->templateFunction($function_tag) 6.7.4 $smarty->register->modifier($modifier_name, $modifier_impl) , 。 ; array(&$object, $method) , &$object , $method ; array(&$ class, $method) , $class ,$method 。 : $hanobj = new han(); $smarty->setcaching(true); $smarty->register->modifier(‘hhh’,array(&$hanobj,’myf’)); # class han{ 。。。。。。 public function myf($string) { return time().$string; } } {$name|hhh nocache=true} # ,nocache true, $smarty->unregister->modifier($modifier) # 6.8 6.8.1 6.1.1 pre 6.1.2 post 6.13 output 6.8.2 libs/plugins block. .php function smarty_block_hhhh($params,$content,&$smarty,&$repeat) # { return " ".$params['fn'].$params['un']." !<br />\r
".$content; } {hhhh fn=$name un=$name1} # aaaaaaa {time()} {/hhhh} , 6.8.3 libs/plugins function. .php function smarty_function_hhhh($params,&$smarty,&$repeat){ # return time()." ".$params['fn'].$params['un']." !<br />\r
"; } {nocache} {hhhh fn=$name un=$name1} # , , {nocache} {/nocache} 6.8.4 libs/plugins modifier. .php function smarty_modifier_hhhh($string) # { return time().$string; } {$name|hhhh nocache=true} # 6.8.5 insert libs/plugins insert. .php function smarty_insert_hhhh($params,&$smarty){ # insert return time()." ".$params['fn']."|".$params['un']." !<br />\r
"; } {insert name="hhhh" fn=$name un=$name1} # ,