首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >代码触发器从缓存输出数据

代码触发器从缓存输出数据
EN

Stack Overflow用户
提问于 2015-05-11 19:28:00
回答 2查看 1.1K关注 0票数 0

我的控制器中有以下函数:

代码语言:javascript
复制
public function cached_icd10() {
        /*
Get information from database and cache the information         */
        $this->load->driver('cache', array('adapter' => 'file'));

        $cacheID = "icd10";
        if (!$cache_data = $this->cache->get($cacheID)) {
            //ge information from the  database 
            $data['icd10_codes'] = $this->icd_10_codes();

            // Save into the cache for 5 minutes
            $this->cache->save($cacheID, $data['icd10_codes'], 300);
            $cache_data = $data['icd10_codes'];
        }
        return $cache_data;

    }

    public function form() {
        //Fetch all ICD10 Codes from the cache file which is icd10

        $cache_data = $this->cached_icd10();


        $this->load->view('form', $cache_data);
    }

第一个函数缓存数据库中的信息,第二个函数将信息传递给名为form的视图。当我尝试从我的视图输出信息时,它抛出一个错误: Message: Undefined variable: cache_data,而当我尝试从控制器输出信息时,它会很好地响应它。使用以下代码:

代码语言:javascript
复制
 <?php
    foreach ($cache_data as $value) {
        echo 'Out put per line is ....:    ' . $value['icd_description'] . ' and the  Id is .... ' . $value['id'] . '<br>';
    }
    ?>

如何将此信息从控制器显示到视图?

EN

回答 2

Stack Overflow用户

发布于 2015-05-11 19:39:23

您可以使用array将缓存数据传递给视图

代码语言:javascript
复制
public function form() {
     //Fetch all ICD10 Codes from the cache file which is icd10
        $cache_data = $this->cached_icd10();
        $data['cache_data']=$cache_data;// create and pass data to array
        $this->load->view('form', $data);
    }

您可以使用以下命令在视图中获取缓存数据

代码语言:javascript
复制
foreach ($cache_data as $value) {
       // your code here
    }
票数 1
EN

Stack Overflow用户

发布于 2019-05-09 03:34:35

代码语言:javascript
复制
$this->load->driver('cache',
        array('adapter' => 'apc', 'backup' => 'file', 'key_prefix' => 'my_')
);

$this->cache->get('foo'); // Will get the cache entry named 'my_foo'

参考网址:https://www.codeigniter.com/userguide3/libraries/caching.html#example-usage

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30166480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档