Codeigniter - 分页无法正常工作

Codeigniter - Pagination not working correctly

我在使用 codeigniter 和分页时遇到了一些问题。问题是我在所有页面上都得到了所有 results/posts。

这是我的代码:

<?php 

class Posts extends CI_Controller{

function __construct(){
    parent::__construct(); 
    $this->load->model('post'); 
}

function index(){
    $data['posts'] = $this->post->get_posts(); 
    $this->load->library('pagination'); 
    $config['base_url']= base_url() .'posts/index/';
    $config['total_rows']= $this->post->get_number_of_posts(); 
    $config['per_page']=1; 
    $this->pagination->initialize($config); 

    $data['pages']=$this->pagination->create_links();
    $this->load->view('index_blog', $data); 

}} ?>

可能有什么问题?

提前致谢。

将此添加到控制器启动并限制到您的模型函数参数

$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['posts'] = $this->post->get_posts($config["per_page"], $page); 

然后是模型函数get_posts

 $this->db->limit($limit, $start);