本文介绍了codeigniter指定限制为NULL在最新的CI版本2.1.2中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一种Codeigniter模型中具有以下 get_authors_list 函数

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();
  }

在升级到Codeigniter 2.1.2之前,我曾使用从控制器中调用此方法的方式

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)

它可以按预期工作,但是升级到codeigniter 2.1.2版后,它不起作用,要使其正常工作,我必须在函数调用中指定限制,如下所示:

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)

指定NULL限制无效,为什么?我在这里做错什么了吗?我正确遵循了Codeigniter的升级说明,但这是我没想到的副作用.

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 !

推荐答案

对,它不起作用,因为在最新版本的CodeIgniter 在其 System/Database/DB_active_rec.php 文件,他们对早期版本的limit函数中的一行进行了更改:

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;

现在是

$this->ar_limit = (int) $value;

因此,(int) null正在转换为0,并且您没有得到任何结果.

So, (int) null is being converted to 0, and, you are not getting any results.

所以我认为您必须完全删除limit调用.为什么仍然需要将其设置为null?

So I think you have to remove the limit call totally. Why do you need to set it to null anyway?

这篇关于codeigniter指定限制为NULL在最新的CI版本2.1.2中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:29