this works in controller.
$this->load->driver('cache'); //working // $data['advisory']=$advisory = $this->cache->memcached->get('advisory'); // if(! $advisory) // { // $data['advisory']=$advisory = $this->mhomework->getbyadvisory($this->teacherid); // $this->cache->memcached->save('advisory' , $advisory); // }
i made library make following can use others.
function cache($key, $data) { $this->ci->load->driver('cache'); $cache = $this->ci->cache->memcached->get($key); if (!$cache) { // there's been miss, run our data function , store $cache = $data($ci); //$cache = $data; $this->ci->cache->memcached->save($key, $cache); } return $cache; }
and in controller changed following gives error.
$data['advisory'] = $this->hwtracker->cache('advisory.'.$this->teacherid, function(&$ci){ return $ci->mhomework->getbyadvisory($this->teacherid); }); // error call member function getbyadvisory() on non-object in ... controller // message: trying property of non-object
my question how can send function library in codeigniter? or can i?
update:
function getbyadvisory($id){ $q="select *, studentid, count(studentid),be_user_profiles.first_name, be_user_profiles.last_name be_user_profiles left join hw_homework on be_user_profiles.user_id= hw_homework.studentid be_user_profiles.advisor = $id group be_user_profiles.user_id order count(studentid) desc"; $query = $this->db->query($q); if ($query->num_rows() > 0) { foreach ($query->result_array() $row) { $data[] = $row; } } else { $data = false; } $query->free_result(); return $data; }
please change library this
function cache($key, $data) { $this->ci->load->driver('cache'); //bind key here $key_details = $data.$key; $cache = $this->ci->cache->memcached->get($key_details); if (!$cache) { // there's been miss, run our data function , store $cache = $this->$data($key); //$cache = $data; $this->ci->cache->memcached->save($key, $cache); } return $cache; } //new advisory function in library function advisory($teacherid){ return $this->ci->mhomework->getbyadvisory($teacherid); }
and in controller call this
$data['advisory'] = $this->hwtracker->cache($this->teacherid,'advisory');
Comments
Post a Comment