Codeigniter分页不会在2页上显示结果

时间:2013-05-30 09:52:13

标签: php codeigniter pagination

我正在使用Codeigniter分页类。

控制器: -

public function index($issue_id = 0)
    {
        if(empty($issue_id))
        {
            $config = array(
               array(
                     'field'   => 'seltype',
                     'label'   => 'Type of issue',
                     'rules'   => 'trim'
                  ),
               array(
                     'field'   => 'txttitle',
                     'label'   => 'Title',
                     'rules'   => 'trim|required'
                  ),
            );
            $this->form_validation->set_rules($config);


            $this->load->library('pagination');

            $config['base_url'] = site_url()."/new_issues";
            $config['total_rows'] = $this->all_model->total_new_level_records(1);

            $offset = $this->uri->segment(3);
            $config['per_page'] = 9; 

            $config['uri_segment'] = 3;
            $config['use_page_numbers'] = TRUE;

            $this->pagination->initialize($config); 

            $data['level_one'] = $this->all_model->new_level_issues(1,$config["per_page"], $config['uri_segment']);

            $data["links"] = $this->pagination->create_links();

            $this->load->view("new_issues_page", $data);
        }
}

我从db获得了总共33行,而且我可以在我的视图页面中看到分页显示1,2,3 Last。但是当我点击2链接时,它显示没有结果。

编辑: - 我点击2页时获得的网址是: - http://www.example.com/new_issues/2

我也尝试打印: - $offset = $this->uri->segment(3);但它没有显示任何内容。

2 个答案:

答案 0 :(得分:0)

尝试替换喜欢,它应该是url的第三段

$config['uri_segment'] = 3;

你的base_url应该像

$config['base_url'] = site_url()."/new_issues/index";

不是其他新功能

答案 1 :(得分:0)

在调用模型函数之前,只需加载模型$this->load->model('all_model')

$this->load->model('all_model');

        $config = array();
        $config['base_url'] = site_url("controller/method");
        $config['total_rows'] = $this->db->get_where('table name',array('where condition'))-> num_rows();
        $config['per_page'] = 9;
        $config['uri_segment'] = 5;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();