0
votes

I have been doing a project in Codeigniter and the pagination is not fully working. It is showing and going to the different pages however the number of the current page doesn't change. Always points to page 1, even if we are in the last page and the products from the last page are shown..

This is my code.

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

At the begining I wasn't using uri_segment. I tried with it, and even $page/10 since there are 10 clients shown per page, but it isnt working.

The pagination is passed to the view and printed.

1
how about your query? do you optimize it for the offset? - Drixson OseƱa

1 Answers

0
votes

I found the solution if

$config['uri_segment'] = $page;

is not recognized.

This is how my code looks like now.

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