使用Codeigniter生成页码链接时出错


Error in generating page number links using Codeigniter

我正在使用Codeigniter创建分页,我的问题是我在显示我的URL中的页码链接时出错。

我转到第二页我的URL是这样的:
http://localhost/my_project/inbound/listing/1

if page 3

http://localhost/my_project/inbound/listing/2

这是我的控制器

    $config = array();
    $config['base_url'] = base_url('inbound/listing');
    $config['total_rows'] = $this->mod->countList();
    $config['per_page'] = 1;
    $config['uri_segment'] = 3;
    //fd($config);
    $this->pagination->initialize($config);
    $page   =   ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    fp($page, 'pink'); //print out result
    $order  =   ($this->input->get('order'))? $this->input->get('order'): '';
    $sort   =   ($this->input->get('sort'))? $this->input->get('sort'): '';
    // Query data
    $data['data_list'] = $this->mod->listing($config['per_page'], $page);  //where, limit, page, field, sort     
    fP($data['data_list']); //print out result
    $data['pagination'] = $this->pagination->create_links();

然后是生成链接的模型:

function listing($limit, $start)
    {
        //DATE_FORMAT(`post_date_added`, "%m/%d/%Y %H:%i") as `proper_post_date_added`,
        $this->db->select('*');
        $this->db->from('inventory');
        $this->db->limit($limit, $start);

        $query = $this->db->get();
        //$rows = $query->result_array();
        if($query->num_rows() > 0) {
            foreach($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
    }
你能帮我一下吗?

如果您想根据您的url转到页码,修改您的列表函数如下:

function listing($limit, $start)
{
    $offset_1 = $start - $limit;
    $offset_2 = $offset_1 < 0 ? 0 : $offset_1;
    //DATE_FORMAT(`post_date_added`, "%m/%d/%Y %H:%i") as `proper_post_date_added`,
    $this->db->select('*');
    $this->db->from('inventory');
    $this->db->limit($limit, $offset_2);

    $query = $this->db->get();
    //$rows = $query->result_array();
    if($query->num_rows() > 0) {
        foreach($query->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return false;
}