1
votes

I am using the pagination class in my codeigniter application. The pagination links show up fine, ie, I suppose the right number of links eg. 1 2 3 4 5 >, and the page loads up with the amount of entries I specified per page.

The error is when I click on one of the links to go to the next set of entries, it says "page cannot be found".

The controller:

public function index()
    {

      $config["base_url"] = base_url().'tester';

            $config["total_rows"] = $this->test_model->count_entries();

            $config["per_page"] = 3;

            $config['uri_segment'] = 2;

            $config["num_links"] = 10;

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

         $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
         $q1=$this->test_model->get_entries($config["per_page"],$page);
             $links = $this->pagination->create_links();
}

The Model:

public function count_entries() {

        $this->db->where('approved', 0);
        $this->db->from('tested');

        return $this->db->count_all_results();

    }

public function get_entries($limit, $start)
    {
         $this->db->limit($limit, $start);

        $this->db->where('approved', 0);

$q = $this->db->get('tested');
$data = $q->result_array();
        return  $data;
    }

The URL of the page is http://localhost:8080/CIAPP/tester, with http://localhost:8080/CIAPP/ set as my base_url in my config file. CIAPP is the application directory and tester is my controller.

The error occurs when I click on any of the pagination links which goes to url http://localhost:8080/CIAPP/tester/3 which says "page not found".

When I click on link 2 the url is /3, when I click on link 3 the url is /6. I suppose this is because I specified 3 per page.

How do I fix this so that when I click the pagination links, the pages with the appropriate entries load up?

2

2 Answers

5
votes

CIAPP - application directory tester- controller class

are you using any function inside tester..??

if then,

base_url().'tester/function_name';

2
votes

You are going to want to set the "use_page_numbers" value to TRUE in your pagination configuration.

$config['use_page_numbers'] = TRUE,