Codeigniter中的分页不会更改页面

时间:2014-10-21 09:54:31

标签: php codeigniter pagination

我一直在Codeigniter做一个项目,并且分页不完全正常。 它显示并转到不同的页面,但当前页面的数量不会改变。总是指向第1页,即使我们在最后一页并且显示了最后一页的产品..

这是我的代码。

            $count=$this->client_model->get_clients_count();
            $this->load->library("pagination");
            //Configuration
            $config['first_tag_open'] = $config['last_tag_open']= $config['next_tag_open']= $config['prev_tag_open'] = $config['num_tag_open'] = '<li>';
            $config['first_tag_close'] = $config['last_tag_close']= $config['next_tag_close']= $config['prev_tag_close'] = $config['num_tag_close'] = '</li>';
            $config['cur_tag_open'] = '<li class="active">';
            $config['cur_tag_close'] = "</li>";
            $config['base_url'] = base_url("employee/clients/");
            $config['total_rows'] = $count->count;
            $config['per_page'] = 10;
            $config['uri_segment'] = $page;
            $this->pagination->initialize($config);
            $pagination= $this->pagination->create_links();

一开始我没有使用uri_segment。我尝试了它,甚至$ page / 10,因为每页显示10个客户端,但它不起作用。

分页传递到视图并打印。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案

$config['uri_segment'] = $page;

无法识别。

这就是我的代码现在的样子。

        $count=$this->client_model->get_clients_count();
        $this->load->library("pagination");

        //Configuration
        $config['first_tag_open'] = $config['last_tag_open']= $config['next_tag_open']= $config['prev_tag_open'] = $config['num_tag_open'] = '<li>';
        $config['first_tag_close'] = $config['last_tag_close']= $config['next_tag_close']= $config['prev_tag_close'] = $config['num_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active">';
        $config['cur_tag_close'] = "</li>";
        $config['base_url'] = base_url("employee/clients/");
        $config['total_rows'] = $count->count;
        $config['per_page'] = 10;

        //Initialization
        $this->pagination->initialize($config);
        //new line of code 
        $this->pagination->cur_page = $page;
        $pagination= $this->pagination->create_links();