当下一个/上一页或第二页被点击时,codeigniter分页重定向到同一页面

时间:2015-06-05 06:03:36

标签: php codeigniter pagination

我是CodeIgniter Pagination的新手。我有一个显示用户的表。我希望它是分页的。但我的问题是它在页面中显示相同的数据。我的意思是,当我点击第二页或下一页时。它重定向到同一页面。怎么解决这个问题?

 $config = array();
    $config["base_url"] = site_url('User/viewUsers/');
    $config['total_rows'] =  $this->db->get('user')->num_rows();
    $config["per_page"] = 10;
    $config["num_links"] = 1;
    $config['uri_segment'] = 4;
    //$config['use_page_numbers'] = TRUE;

    $config['enable_query_strings'] = TRUE;

    //Adding Enclosing Markup
    $config['full_tag_open'] = '<p><ul  class="pagination">';
    $config['full_tag_close'] = '</ul></p><!--pagination-->';
    //Customizing the First Link
    $config['first_link'] = '&laquo; First';
    $config['first_tag_open'] = '<li class="prev page">';
    $config['first_tag_close'] = '</li>';
    //Customizing the Last Link
    $config['last_link'] = 'Last &raquo;';
    $config['last_tag_open'] = '<li class="next page">';
    $config['last_tag_close'] = '</li>';
    //Customizing the "Next" Link
    $config['next_link'] = 'Next &rarr;';
    $config['next_tag_open'] = '<li class="next page">';
    $config['next_tag_close'] = '</li>';
    //Customizing the "Previous" Link
    $config['prev_link'] = '&larr; Previous';
    $config['prev_tag_open'] = '<li class="prev page">';
    $config['prev_tag_close'] = '</li>';
    //Customizing the "Current Page" Link
    $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
    $config['cur_tag_close'] = "<span class='sr-only'></span></a></li></li>";
    //Customizing the "Digit" Link
    $config['num_tag_open'] = '<li class="page">';
    $config['num_tag_close'] = '</li>';

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

    $page = $this->uri->segment(4);
    //$page = ($this->uri->segment(4) > 0) ? $this->uri->segment(4) : 0;
    $data = array(); 
    $data['users'] = $this->user_model->getUserList($config["per_page"], $page);

    $data['links'] = $this->pagination->create_links();
    $data['fullname'] = NULL; 
            $this->load->view('include/header');
        $this->load->view('admin/viewUsers',$data); 
        $this->load->view('include/footer');

型号:

public function getUserList($limit,$start){
    $query = array();
    $this->db->limit($limit, $start);
    $this->db->order_by('user_id'); 
    $query = $this->db->get('user');  
    return $query->result();
}

1 个答案:

答案 0 :(得分:1)

更改此

控制器中的

<?php

    $count = $this->db->get('user')->num_rows();

    $config['base_url'] = base_url().'User/viewUsers/';
    $config['total_rows'] = $count;
    $config["per_page"] = 10;
    $config['uri_segment'] = 3;
    $limit = $config['per_page'];

//    $config['enable_query_strings'] = TRUE;

    $config['full_tag_open'] = '<ul class="pagination">';
    $config['full_tag_close'] = '</ul>';
    $config['first_link'] = false;
    $config['last_link'] = false;
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['prev_link'] = '&laquo';
    $config['prev_tag_open'] = '<li class="prev">';
    $config['prev_tag_close'] = '</li>';
    $config['next_link'] = '&raquo';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="active"><a href="#">';
    $config['cur_tag_close'] = '</a></li>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';

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

 $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

    $data['users'] = $this->user_model->getUserList($limit, $page);
    $data['links'] = $this->pagination->create_links();
    $data['fullname'] = NULL;

    $this->load->view('include/header');
    $this->load->view('admin/viewUsers',$data);
    $this->load->view('include/footer');

在模型中

    public function getUserList($limit,$page)
{
    $query = $this->db->query("SELECT * FROM user LIMIT $page, $limit");
    $result = $query->result_array();
    return $result;
}