ci文件缓存使用,可以用来实现多模板切换 改写URL辅助函数

//2015年2月28日15:13:41

$this->load->driver('cache', array('adapter' => 'file'));//加载适配器
//请注意,最好用新版本
$tpl='default';

$this->cache->file->save('template', $tpl, 999);
$this->cache->file->save('存的文件名或者叫ID', '存进去的值', '存在的时间');
//写一个竟可能大的时间可以表示无线
$template =$this->cache->get('template');//获取template的值
$this->cache->delete('template');//删除template的缓存文件
var_dump($this->cache->cache_info());//获取所有缓存的文件的详细信息
$this->cache->clean();//删除所有的缓存的文件
var_dump($this->cache->get_metadata('template'));//获取template的缓存的详细信息
也可以用来缓存微信缓存7200秒的key

a:3:{s:4:"time";i:1425107444;s:3:"ttl";i:999;s:4:"data";s:7:"default";}
 其实思路是一样的
如果你不想写写缓存文件,不放心写入权限还有一个
自己写模板管理
很简单,在系统整个全局做一个tpl_url()函数,如何写,就直接扩展url_helper帮助类

MY_url_helper放在application的helper

在url_helper里面
加入
if ( ! function_exists('tpl_url'))
{
function tpl_url()
{ 
$CI= &get_instance();//获得超级对象
$CI->load->model('admin_model');//不能使用$this
$data=$CI->admin_model->list_check($table= 'configure');查询配置文件获得当前模板的views文件夹下面url,list_check是表所有数据的方法
$tpl_url = base_url().'application/views/'.$data['0']['web_tpl'].'/';
return $tpl_url;
}
}

list_check的方法在admin_model里面

public function list_check($table) {
$query = $this->db->get($table);
return $query->result_array(); 
}

这样在views里面的模板就直接可以<?php echo tpl_url()?>和base_url的使用方法一样,这样就可以简单的实现多模板切换的url根据不同模板url切换

这个使用起来有些像dedecms显示全局url的方法

 

 
 

 

posted on 2015-02-28 15:20  zh7314  阅读(738)  评论(0编辑  收藏  举报