问题
I have following get_authors_list function in one of my Codeigniter model
function get_authors_list($limit,$offset){
$data = array();
$this->db->select('*')->from('authors')->limit($limit,$offset)->order_by('id','desc');
$query = $this->db->get();
if ($query-> num_rows() > 0){
$data = $query->result_array();
}
return $data;
$q->free_result();
}
Before upgrading to Codeigniter 2.1.2, I used call this method from my controller as
$data['authors'] = $this->author_model->get_authors_list(NULL, 0)
and it worked as expected but after upgrading to codeigniter version 2.1.2 it doesn't work, to get it working I had to specify limit as follows in my function call
$data['authors'] = $this->author_model->get_authors_list(50, 0)
That's specifying limit to NULL is not working, why? Am I doing anything wrong here? I followed Codeigniter's upgrade instruction correctly but it's some side effect I didn't expect.
Any explanation is welcome. Thanks !
回答1:
Right, it won't work because, in the latest version of CodeIgniter in their System/Database/DB_active_rec.php file, they made a change to a line in limit function of earlier versions:
$this->ar_limit = $value;
is now,
$this->ar_limit = (int) $value;
So, (int) null is being converted to 0, and, you are not getting any results.
So I think you have to remove the limit call totally. Why do you need to set it to null anyway?
回答2:
It doesn't work anymore. There's been a change in the source code that will now ignore NULL value. See this commit.
来源:https://stackoverflow.com/questions/12365432/codeigniter-specifying-limit-to-null-not-working-in-latest-ci-version-2-1-2