codeigniter specifying limit to NULL not working i

2019-07-16 08:41发布

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 !

2条回答
太酷不给撩
2楼-- · 2019-07-16 09:30

It doesn't work anymore. There's been a change in the source code that will now ignore NULL value. See this commit.

查看更多
劳资没心,怎么记你
3楼-- · 2019-07-16 09:35

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?

查看更多
登录 后发表回答