$this->分页->create_links();返回空白字符串


$this->pagination->create_links(); returning blank string

<?php
    class Books extends CI_Controller {
    function __construct() {
    parent::__construct();
    $this->load->helper('url');
  }
  function index() {
    // load pagination class
    $this->load->library('pagination');
    $config['base_url'] = base_url().'books/index/';
    $config['total_rows'] = 2;
    $config['per_page'] = '5';
    $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';
    $this->pagination->initialize($config);
    echo $this->pagination->create_links();
  }
    }
?>

create_links(); 函数似乎不起作用。我没有收到任何错误,但它只返回一个空白字符串。我已经尝试了 http://blip.tv/nettuts/codeigniter-from-scratch-day-7-2690301 和 http://godbit.com/article/pagination-with-code-igniter 教程。

我知道文档说 http://codeigniter.com/user_guide/libraries/pagination.html The create_links() function returns an empty string when there is no pagination to show.但是我该如何解决这个问题?谢谢!

块引用

我认为

是因为您没有任何分页数据。这是一个工作示例:

    $this->load->model('books_model', 'books');
    $offset = $this->uri->segment(n);
    $per_page = 5;
    $total = $this->books->total();
    $data['result'] = $this->books->get_all($per_page, $offset);
    $config['base_url'] = base_url().'books/index/';
    $config['total_rows'] = $total;
    $config['per_page'] = $per_page;
    $this->load->vars($data); // !!!
    $this->pagination->initialize($config);

我希望这对你有帮助