<?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.
但是我如何解决这个问题呢?
谢谢你!
块引用
答案 0 :(得分:3)
我认为因为您没有任何分页数据。这是一个有效的例子:
$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);
我希望这会对你有所帮助