简体   繁体   中英

CodeIgniter pagination links not rendering

In my view, the links for pagination is not rendering.It was working earlier this day, don't know what I did wrong to make the generating of links fail.

public function index() {
    $data['user'] = $this->session->userdata();
    $_SESSION['nav'] = 1;
    $this->load->library('pagination');
    $page = 2;
    $offset = $this->uri->segment(3);
    $config['uri_segment'] = 4;
    $config['base_url'] = base_url() . 'assigner/index/';
    $config['total_rows'] = $this->TasksModel->countPostedTasks();
    $config['per_page'] = $page;

    $config['full_tag_open'] = "<ul class='pagination'>";
    $config['full_tag_close'] = "</ul>";
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
    $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
    $config['next_tag_open'] = "<li>";
    $config['next_tagl_close'] = "</li>";
    $config['prev_tag_open'] = "<li>";
    $config['prev_tagl_close'] = "</li>";
    $config['first_tag_open'] = "<li>";
    $config['first_tagl_close'] = "</li>";
    $config['last_tag_open'] = "<li>";
    $config['last_tagl_close'] = "</li>";
    $this->pagination->initialize($config);
    $data['links'] = $this->pagination->create_links();

    $data['tasks'] = $this->TasksModel->getPostedTasks($page, $offset);
    $this->load->view('assigner/header', $data);
    $this->load->view('assigner/index', $data);
}

You will need to define the number of links the pagination library should show. Add this line to your code.

$config['num_links'] = round($config['total_rows'] / $config['per_page']);

Use it like this:

public function index() {
    $data['user'] = $this->session->userdata();
    $_SESSION['nav'] = 1;
    $this->load->library('pagination');

    $per_page = 2;

    $config['uri_segment'] = 3;
    $config['base_url'] = base_url() . 'assigner/index/';
    $config['total_rows'] = $this->TasksModel->countPostedTasks();
    $config['per_page'] = $per_page;

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $offset = ($page == 0 ? 0 : ($page - 1) * $config["per_page"]);

    $this->pagination->initialize($config);
    $data['links'] = $this->pagination->create_links();

    $data['tasks'] = $this->TasksModel->getPostedTasks($page, $offset);

    $data['total_page'] = ceil($config['total_rows'] / $config['per_page']);

    $this->load->view('assigner/header', $data);
    $this->load->view('assigner/index', $data);
}

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