亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
Smarty模板編譯引擎 I.開始 第一章. 什么是Smarty? 第二章. 安裝 要求 基本安裝 擴(kuò)展設(shè)置 II.模板設(shè)計者篇 第三章.基本語法 注釋 函數(shù) 屬性 第四章.變量 從PHP分配的變量 Associative arrays Array indexes Objects 從配置文件讀取的變量 {$smarty}保留變量 Request variables {$smarty.now} {$smarty.const} {$smarty.capture} {$smarty.config} {$smarty.section} {$smarty.template} 第五章.變量調(diào)節(jié)器 capitalize count_characters cat count_paragraphs count_sentences count_words date_format default escape indent lower nl2br regex_replace replace spacify string_format strip strip_tags truncate upper wordwrap 第六章.組合修改器 第七章.內(nèi)建函數(shù) capture config_load foreach include include_php insert if ldelim literal php section index index_prev index_next iteration first last rownum loop show total strip 第八章.自定義函數(shù) assign counter cycle debug eval fetch html_checkboxes html_image html_options html_radios html_select_date html_select_time html_table math mailto popup_init popup textformat 第九章.配置文件 第十章.調(diào)試控制臺 III.模板程序員篇 第十一章 常量 SMARTY_DIR 第十二章 變量 $template_dir $compile_dir $config_dir $plugins_dir $debugging $debug_tpl $debugging_ctrl $global_assign $undefined $autoload_filters $compile_check $force_compile $caching $cache_dir $cache_lifetime $cache_handler_func $cache_modified_check $config_overwrite $config_booleanize $config_read_hidden $config_fix_newlines $default_template_handler_func $php_handling $security $secure_dir $security_settings $trusted_dir $left_delimiter $right_delimiter $compiler_class $request_vars_order $compile_id $use_sub_dirs $default_modifiers $default_resource_type 第十三章.方法 append append_by_ref assign assign_by_ref clear_all_assign clear_all_cache clear_assign clear_cache clear_compiled_tpl clear_config config_load display fetch get_config_vars get_registered_object get_template_vars is_cached load_filter register_block register_compiler_function register_function register_modifier register_object register_outputfilter register_postfilter register_prefilter register_resource trigger_error template_exists unregister_block unregister_compiler_function unregister_function unregister_modifier unregister_object unregister_outputfilter unregister_postfilter unregister_prefilter unregister_resource 第十四章.緩存 Setting Up Caching Multiple Caches Per Page Cache Groups Controlling Cacheability of Plugins' Output 第十五章.高級特點 Objects Prefilters Postfilters Output Filters Cache Handler Function Resources Templates from $template_dir Templates from any directory Templates from other sources Default template handler function 第十六章.以插件擴(kuò)展Smarty How Plugins Work Naming Conventions Writing Plugins Template Functions Modifiers Block Functions Compiler Functions Prefilters/Postfilters Output Filters Resources Inserts Ⅳ.高級特點 第十七章.疑難解答 Smarty/PHP errors 第18章.使用技巧和經(jīng)驗 Blank Variable Handling Default Variable Handling Passing variable title to header template Dates WAP/WML Componentized Templates Obfuscating E-mail Addresses 第十九章. 相關(guān)資源 第二十章. 漏洞
characters

Controlling Cacheability of Plugins' Output控制插件輸出的緩沖能力

Since Smarty-2.6.0 plugins the cacheability of plugins can be declared when registering them. The third parameter to register_block, register_compiler_function and register_function is called $cacheable and defaults to true which is also the behaviour of plugins in Smarty versions before 2.6.0

自從Smarty-2.6.0插件以來,如果注冊它們,則插件的緩存能力能夠被重新聲明的。register_block,register_compiler_function 和register_function的第3個參數(shù)就是$ cacheable , 并且它的值默認(rèn)為true。當(dāng)然,在2.6.0版本之前它的默認(rèn)值也是這樣的。

When registering a plugin with $cacheable=false the plugin is called everytime the page is displayed, even if the page comes from the cache. The plugin function behaves a little like an insert function.

當(dāng)用$cacheable=false來這冊一個插件,則每次這個頁面被輸出的時候,這個插件就會被使用,即使這個頁面來自緩存。這個插件函數(shù)的行為有點像這個函數(shù)insert。

In contrast to {insert} the attributes to the plugins are not cached by default. They can be declared to be cached with the fourth parameter $cache_attrs . $cache_attrs is an array of attribute-names that should be cached, so the plugin-function get value as it was the time the page was written to cache everytime it is fetched from the cache.

和{insert}相反,插件的屬性默認(rèn)是不緩存的。通過使用第四個參數(shù) $cache_attrs ,它們能夠被重新聲明為緩存的。 $cache_attrs 是一個屬性名字的數(shù)組,可以被緩存,所以每次當(dāng)它被從緩存中取出的時候,這個插件函數(shù)獲得值-----因為這個頁面會被寫入用來緩存。

Example 14-10. Preventing a plugin's output from being cached

例14-10.阻止插件從緩存中輸出

index.php:

require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;

function remaining_seconds($params, &$smarty) {
 $remain = $params['endtime'] - time();
 if ($remain >=0)
 return $remain . " second(s)";
 else
 return "done";
}

$smarty->register_function('remaining', 'remaining_seconds', false, array('endtime'));

if (!$smarty->is_cached('index.tpl')) {
 // fetch $obj from db and assign...
 $smarty->assign_by_ref('obj', $obj);
}

$smarty->display('index.tpl');


index.tpl:

Time Remaining: {remain endtime=$obj->endtime}

The number of seconds till the endtime of $obj is reached changes on each display of the page, even if the page is cached. Since the endtime attribute is cached the object only has to be pulled from the database when page is written to the cache but not on subsequent requests of the page.

直到$obj運(yùn)行結(jié)束,時間的秒數(shù)在每一個頁面輸出的時候會改變,即使這個頁面被緩存。只要結(jié)束時間屬性被緩存,當(dāng)頁面被寫入到緩存但是沒有對這個頁面接著的請求的時候?qū)ο笾皇遣坏貌恢匦聫臄?shù)據(jù)庫里取出而已。

?

Example 14-11. Preventing a whole passage of a template from being cached

例14-11.阻止一個模板文件的 整篇被緩存

index.php:

require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;

function smarty_block_dynamic($param, $content, &$smarty) {
 return $content;
}
$smarty->register_block('dynamic', 'smarty_block_dynamic', false);

$smarty->display('index.tpl');


index.tpl:

Page created: {"0"|date_format:"%D %H:%M:%S"}

{dynamic}

Now is: {"0"|date_format:"%D %H:%M:%S"}

... do other stuff ...

{/dynamic}

When reloading the page you will notice that both dates differ. One is "dynamic" one is "static". You can do everything between {dynamic}...{/dynamic} and be sure it will not be cached like the rest of the page.

當(dāng)重新加載這個頁面,你將會注意到這兩個日期不同。一個是“動態(tài)“,一個是“靜態(tài)”。你能夠在{dynamic}...{/dynamic}之間作任何事情,并且保證它將不會像剩下的頁面一樣被緩存。

Previous article: Next article: