php - Code igniter Outputting data from cache -
i have following functions in controller :
public function cached_icd10() { /* information database , cache information */ $this->load->driver('cache', array('adapter' => 'file')); $cacheid = "icd10"; if (!$cache_data = $this->cache->get($cacheid)) { //ge information database $data['icd10_codes'] = $this->icd_10_codes(); // save cache 5 minutes $this->cache->save($cacheid, $data['icd10_codes'], 300); $cache_data = $data['icd10_codes']; } return $cache_data; } public function form() { //fetch icd10 codes cache file icd10 $cache_data = $this->cached_icd10(); $this->load->view('form', $cache_data); } the first function caches information database , second 1 passes view called form. when try output information view , fails throwing error : message: undefined variable: cache_data while when try controller echoes well. using code below :
<?php foreach ($cache_data $value) { echo 'out put per line ....: ' . $value['icd_description'] . ' , id .... ' . $value['id'] . '<br>'; } ?> how can display information controller view ?
you can pass cache data view using array
public function form() { //fetch icd10 codes cache file icd10 $cache_data = $this->cached_icd10(); $data['cache_data']=$cache_data;// create , pass data array $this->load->view('form', $data); } you can cache data in view with
foreach ($cache_data $value) { // code here }
Comments
Post a Comment