CodeIgniter分页链接无法呈现

时间:2017-03-06 16:12:21

标签: php codeigniter pagination

在我看来,分页的链接不是渲染。它今天早些时候工作,不知道我做错了什么使链接生成失败。

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);
}

2 个答案:

答案 0 :(得分:0)

您需要定义分页库应显示的链接数。 将此行添加到您的代码中。

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

答案 1 :(得分:0)

像这样使用:

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);
}