楼主,我把https://gist.github.com/1142184#file_query_cache.php这个文件放到了我的application\helpers文件夹下,并在控制器里也LOAD了,但是页面显示空白,开始我以为是我的HELPERS添加有问题,于是我一步一步试最后把你的这个函数内容删减成只有echo "OK";于是页面就可以显示OK了,我又排除一步一步试if( ! in_array($model, $CI->load->_ci_models, TRUE))这句里的$CI->load->_ci_models这个一添加起就无法显示,不知道为什么,后我又把这个HELPER放到系统里的HELPER文件里里,问题依然。因为这步都过不了,后面的语句就都无法运行了!望觖!
注:还有我在$CI = & get_instance();这句时,返回的结果为空!
在入口文件index.php文件中,打开php的错误报告:
error_reporting(E_ALL);
ini_set('display_errors', 1);
找到真实的php错误,然后贴上来再讨论。 3Q {:soso_e179:} 期待文件缓存版本 backwang 发表于 2012-4-15 08:36 static/image/common/back.gif
楼主,我把https://gist.github.com/1142184#file_query_cache.php这个文件放到了我的application\\helpers ...
我也遇到类似问题
$CI->load->_ci_models这个好像是私有属性,不能外部访问 mark{:1_1:}{:1_1:} 本帖最后由 benfeng 于 2013-7-2 10:12 编辑
saturn 发表于 2012-4-16 23:18 static/image/common/back.gif
在入口文件index.php文件中,打开php的错误报告:
error_reporting(E_ALL);
测试了下代码
$CI = & get_instance();
$data = $CI->load->_ci_models;
var_dump($data);
返回下面的错误信息
Fatal error: Cannot access protected property CI_Loader::$_ci_models in ...\controllers\welcome.php on line XX
function query_cache($key, $model, $method, $params = array(), $ttl = 1296000) {
$CI = & get_instance();
// 如果是本地测试等不支持memcache的环境,直接从model中获取数据后返回
if (!$CI->cache->memcached->is_supported()) {
// model是否已经加载?
// Load models on demand
if (!in_array($model, $CI->load->_ci_models, TRUE)) {
$CI->load->model($model);
}
// Ref this model
$handler = & $CI->$model;
return call_user_func_array(array($handler, $method), $params);
}
// 如果数据没有被缓存或者已经过期
if (!$data = $CI->cache->memcached->get($key)) {
// model是否已经加载?
// Load models on demand
if (!in_array($model, $CI->load->_ci_models, TRUE)) {
$CI->load->model($model);
}
// Ref this model
$handler = & $CI->$model;
// 从model中获取数据
$data = call_user_func_array(array($handler, $method), $params);
// 提醒: 空结果 (0, FALSE) 会忽略!
if (!empty($data)) {
// 缓存该数据
$CI->cache->memcached->save('result_'.$key, $data, $ttl);
//注意所有数据缓存加了一个‘result_’前缀,以便跟output_,以及session区分
}
}
return $data;
}
页:
1
[2]