【问题标题】:CodeIgniter: Pagination displaying links but not showing certain results per pageCodeIgniter:分页显示链接但不显示每页的某些结果
【发布时间】:2014-10-03 15:46:03
【问题描述】:

嗨,这可能很明显,但我是分页新手,我认为 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>

编辑:我是否必须在某处配置正在分页的数据或函数的链接是否可以做到这一点?

【问题讨论】:

  • 如何回显'
    ';打印_r($字段);回声'
    ';看起来像?
  • 它打印出我在第 1 页上的每个数组
  • and 2 etc,就像链接指向完全相同的东西,只是没有限制。
  • 另外,如果可以的话,我建议从 Codeigniter 转移到 laravel。易于学习和加载的库,让您的生活更轻松。
  • @seanyt123 我知道它的作用,我想知道它的外观:)

标签: php codeigniter hyperlink pagination


【解决方案1】:

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

【讨论】:

  • 我很抱歉,但这个答案并没有真正的帮助,uri_segment 不是必需的配置,它有一个默认值,而且我的问题不是看到分页链接,我可以看到它们很好,因为我可以使用 echo $this->pagination->create_links();在我的控制器中,就像我看到它们一样,问题是结果不受限制,每个页面都显示所有结果。
猜你喜欢
  • 1970-01-01
  • 2017-12-01
  • 1970-01-01
  • 2017-10-17
  • 2017-10-18
  • 2013-04-07
  • 2013-10-14
  • 1970-01-01
  • 2013-05-03
相关资源
最近更新 更多