【问题标题】:$this->pagination->create_links(); returning blank string$this->pagination->create_links();返回空白字符串
【发布时间】:2011-05-22 04:22:59
【问题描述】:
<?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-2690301http://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. 但是我该如何解决呢? 谢谢你!

块引用

【问题讨论】:

    标签: php codeigniter pagination


    【解决方案1】:

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

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

    希望对你有帮助

    【讨论】:

    • 如果没有模型,可以尝试对数组进行分页:$data = array('page1', 'page2') 等。
    • 是的,教程从未提到必须将 $data 加载为 vars $this->load->vars($data)。我认为它们可能有点过时了。
    猜你喜欢
    • 2023-03-29
    • 2018-02-16
    • 2016-04-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 1970-01-01
    • 2021-10-09
    • 2019-10-13
    相关资源
    最近更新 更多