link in pagination does not work

2019-08-23 10:36发布

问题:

I am trying to make a pagination and I almost get it, but when I change one page to another (click page 1, later click page 2) does not work, but when I do manually it works. That is becouse when I click in the links in my browser show this:&page=40, and manually I only put the 40. I do not know why is that.

this is my Controller

function Test ($value){
if($value =='1'){
  $config['per_page'] = 20;
  $config['num_links'] = 10;
  $config["total_rows"] = $this->db->get('normas')->num_rows();
  $data['query'] = $this->db->get('normas', $config['per_page'], $this->uri->segment(4));
  $this->pagination->initialize($config);
  $data["links"] = $this->pagination->create_links();

 $this->load->view('template/general_template/template', $data);
    }
}

My view

<?php 
    foreach ($query->result() as $row) {
    echo '<p>'. $row->norma.'</p>';
    } 
echo $links;
?>

Please help!!, thanks in advance.

回答1:

Looking at your code, seems like you're missing the

$config['cur_page'] = $this->uri->segment(4);

and

$config['base_url'] = 'http://yoursite.com/index.php/test/page/'; 

take a look at https://www.codeigniter.com/userguide3/libraries/pagination.html



回答2:

I had to change $config['page_query_string']== FALSE becouse I had it in TRUE

$config[‘page_query_string’] = TRUE;

By default, the pagination library assume you are using URI Segments, and >constructs your links something like:

http://example.com/index.php/test/page/20 If you have $config['enable_query_strings'] set to TRUE your links will >automatically be re-written using Query Strings. This option can also be >explicitly set. Using $config['page_query_string'] set to TRUE, the pagination >link will become:

http://example.com/index.php?c=test&m=page&per_page=20

I found this in the Codeigniter documentation CodeIgniter documentation