如何在两次调用相同模型时释放编码器结果


how to free codeigniter results while calling the same model twice

我有一种情况,我用codeigniter写了一个基本模型,所有模型都从它扩展,基本模型有一个函数

public function load_all_by_keys($array, $limit = 0, $offset = 0) {
  if ($limit) {
    $query = $this->database->get_where($this::DB_TABLE, $array, $limit, $offset);
  } else {
    $query = $this->database->get_where($this::DB_TABLE, $array);
  }
  $ret_val = array();
  $class = get_class($this);
  foreach ($query->result() as $row) {
    $model = new $class;
    $model->populate($row);
    $ret_val[$row->{$this::DB_TABLE_PK}] = $model;
  }
  return $ret_val;
}

在这个函数中我可以得到例如,学校的类别是Abet

$abet = new School_Model();
// this query will get all schools with by column category whose value is Abet, thats fine
$abetSchools = $abet-?load_all_by_keys(array('category'=>'Abet'));
$primary = new School_Model();
// This second query fails with the error Fatal error: Call to a member function result() on a non-object
$primarySchools = $primary-?load_all_by_keys(array('category'=>'Primary'))

有人能帮帮忙吗

$this->db->flush_cache()

此函数删除活动记录缓存中的所有项(参考http://ellislab.com/codeigniter/user-guide/database/active_record.html#caching)