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

时间:2014-10-03 06:52:53

标签: php codeigniter hyperlink pagination

嗨,这可能是非常明显的,但我是新的分页,我认为CI的文档真的很垃圾,我期望得到的是一个链接列表,当我点击每一个时,它应该显示我的3个每页的项目,它显示链接列表和链接工作,但它没有显示每页的一定数量的结果,任何人都可以帮助我吗?

我的控制器部分:

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>

编辑:我是否必须在某处配置正在分页的数据,或者该功能的链接是否这样做?

1 个答案:

答案 0 :(得分:0)

您没有指定您的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以接收分页链接。

相关问题