简体   繁体   中英

class CI_Pagination in codeigniter work not properly?

I try to use class pagination of codeigniter, but I came across a problem that the active page of links is always the first page. My Controller Code

<?php
class Users extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->is_logged_in();
    }

    function index()
    {
        $data['main_content'] = 'admin/users_manage';
        $data['left_menu'] = 'admin/left_menu_users';
        $this->load->view('admin/include/templates_login', $data);
    }

    function select()
    {

        $this->load->library('pagination');
        $this->load->library('table');
        $this->load->model('user_model');

        //$this->table->set_heading('Id', 'The Title', 'The Content');

        $config['base_url'] = 'http://localhost/cib/index.php/admin/users/select';
        $config['total_rows'] = $this->db->get('users_view')->num_rows();
        $config['per_page'] = 10;
        $config['num_links'] = 20;
        //$config['full_tag_open'] = '<div class="pagination">';
        //$config['full_tag_close'] = '</div>';

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

        $data['records'] = $this->user_model->getUsers($config['per_page'], $this->uri->segment(4));
        $data['main_content'] = 'admin/users_manage';
        $this->load->view('admin/include/templates_login', $data);
        //$this->load->view('admin/site_view', $data);
    }

    function is_logged_in()
    {
        $is_logged_in = $this->session->userdata('is_logged_in');
        if(!isset($is_logged_in) || $is_logged_in != true)
        {
            echo 'You don\'t have permission to access this page.';
            echo anchor('admin/login/index', 'Login');
            die();
            //$this->load->view('login_form');
        }
    }
} 
?>

And My model code:

<?php
class User_model extends CI_Model
{   
    function validate()
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');

        $this->db->where('username', $username);
        $this->db->where('password', md5($password));       

        $query = $this->db->get('users');
        if($query->num_rows == 1)
        {
            return true;
        }
        return false;
    }

    function getUsers($num="", $offset="")
    {
        $this->db->limit($num,$offset);
        $query = $this->db->get('users_view');
        return $query;
    }
}

and my view page: admin/include/templates_login.php:

<?php $this->load->view('admin/include/header'); ?>

<?php $this->load->view('admin/include/nav');?>

<?php //if (isset($left_menu)) $this->load->view($left_menu)?>

<?php $this->load->view($main_content); ?>

<?php $this->load->view('admin/include/footer'); ?>

admin/users_manage.php:

Super Pagination with CodeIgniter

<?php echo $this->table->generate($records); ?>
<?php echo $this->pagination->create_links(); ?>

The select() function in Controller is the function which uses the class CI_Pagination.I can get the different page of the database.But the links it presents has a problem that the first page link is always active.

在此处输入图片说明

As you can see, the data it presents is actually the 11th page, but the active link is still the first page.(Note that I used bootstrap and codeigniter).

您需要将此添加到活动页面链接的代码中:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM