標籤:param ase instance 預設 reg path etc class index.php
/** * 讀取緩衝,預設為檔案快取,不載入緩衝配置。 * @param string $name 緩衝名稱 * @param $filepath 資料路徑(模組名稱) caches/cache_$filepath/ * @param string $config 配置名稱 */function getcache($name, $filepath=‘‘, $type=‘file‘, $config=‘‘) { if(!preg_match("/^[a-zA-Z0-9_-]+$/", $name)) return false; if($filepath!="" && !preg_match("/^[a-zA-Z0-9_-]+$/", $filepath)) return false; pc_base::load_sys_class(‘cache_factory‘,‘‘,0); if($config) { $cacheconfig = pc_base::load_config(‘cache‘); $cache = cache_factory::get_instance($cacheconfig)->get_cache($config); } else { $cache = cache_factory::get_instance()->get_cache($type); } return $cache->get($name, ‘‘, ‘‘, $filepath);}
如上,getcache()函數。是調用快取檔案資料。
應用:
1.調用類別
<ul><?php $TYPE = getcache(‘type_content‘,‘commons‘);?> //當有多個網站時,快取檔案命名會發生變化,如:type_content_1,type_content_2,type_content_3 所以在調取時,需要做相應修改,
//或者通用寫法 <?php $TYPE = getcache(‘type_content_‘.$siteid,‘commons‘);?>
{loop $TYPE $r}
<li><a href="index.php?m=content&c=type&catid={$catid}&typeid={$r[typeid]}">{$TYPE[$r[typeid]][name]}</a></li>
{/loop}
</ul>
PHPCMS快速建站系列之getcache()的用法