CodeIgniter:分页显示链接,但每页不显示某些结果


CodeIgniter: Pagination displaying links but not showing certain results per page

嗨,这可能真的很明显,但我是分页的新手,我认为CI的文档真的很垃圾,我希望得到的是一个链接列表,当我点击每个链接列表时,它应该每页显示3个我的li项目,它显示了链接列表,链接有效,但每页没有显示一定数量的结果,有人能帮我吗?

我的控制器部分:

public function clist()
    {
        //load the model that gets a list of clients
        $this->load->model('list_model'); 
        //call the function that lists clients and store the return data in a variable
        $fields = $this->list_model->listcliname(); 
        //create an array
        $data = array();
        //assign the data to a key in the array
        $data['fields'] = $fields;
        //pass the array to view for handling and load the view.
        $this->load->library('pagination');
    $config['base_url'] = site_url('clientlist/clist');
    $config['total_rows'] = 500;
    $config['per_page'] = 3;
    $this->pagination->initialize($config);
    echo $this->pagination->create_links();
    $this->load->view('clientlist', $data);

我的观点:

<html>
<head>
<title> client list </title>
<link rel="stylesheet" type="text/css" href="/css/clientlist.css">
<!--  add script to add jquery and add a function that performs a confirm on the event of a click on the delete link. --> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('.confirmation').on('click', function () {
        return confirm('Are you sure?');
    });
    });
</script>
</head>
    <body>
        <div id="container">
            <?php
            foreach($fields as $field) {
                 ?>
                 <ul>
                 <li>
                 <?php echo $field['name']; ?>
                 </li> 
                 <li>
                 <?php echo $field['contact']; ?>
                 </li>
                 <li>
                <form action="clistedit" method="post">
                <input type="hidden" name="sub" value="1" />
                <input type="hidden" name="UID" value="<?php echo $field['UID']?>">
                <button type="submit">edit</button>
                </form>
                </li>
                <li>
                <a href="/clientlist/delete/<?php echo $field['UID']; ?>/" class="confirmation">delete</a>
                <a href="/clientlist/salelead/<?php echo $field['UID']; ?>/">view lead</a>
                </li>
                </ul>
                 <?php
            }
            ?>
        </div>

编辑:我必须在某个地方配置要分页的数据吗?还是函数的链接可以做到这一点?

您没有指定uri的哪个段将包含page_number,也就是分页的uri_segment配置。

通常,页码会在您的uri clientlist/clist 的末尾找到

您的控制器代码将是:

$config['base_url'] = site_url('clientlist/clist');
$config['total_rows'] = 500;
$config['per_page'] = 3;
//Appends the page number to the url
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();

在您看来,您必须回显$pagination才能接收分页链接。