【问题标题】:pagination shows all the result , despite using paginator helper and pagination Cakephp 3.x分页显示所有结果,尽管使用分页器助手和分页 Cakephp 3.x
【发布时间】:2017-03-28 01:30:00
【问题描述】:

所以我是 Cakephp 3.x 的新手,我正在尝试对一组数据进行分页,但问题是所有条目都被显示,底部的导航栏也是显示,我猜它工作正常。

下面是我的控制器。

public $paginate = ['limit' => 2,'order' => ['sample.posts' => 'asc']];

public function initialize()
{
    parent::initialize();
    $this->layout = 'frontend';
    $this->loadComponent('Paginator');
    $this->loadComponent('Flash'); // Include the FlashComponent
}

public function index()
{
    $this->set('Posts', $this->paginate());
    $posts = $this->Posts->find('all');
    $this->set(compact('posts'));
}

这是我的模板文件。

<table>
        <tr>paginate
            <th><?php echo $this->Paginator->sort('ID', 'id'); ?></th>
            <th><?php echo $this->Paginator->sort('Title', 'title'); ?></th>
        </tr>
           <?php foreach($posts as $post): ?>
        <tr>
            <td><?php echo $post['id'] ?> </td>
            <td><?php echo $post['title'] ?> </td>
        </tr>
    <?php endforeach; ?>
</table>

<?php echo $this->Paginator->numbers(); ?>  
<?php echo $this->Paginator->prev('« Previous', array('class' => 'disabled')); ?>
<?php echo $this->Paginator->next('Next »', array('class' => 'disabled')); ?>   
<?php echo $this->Paginator->counter(); ?>

任何帮助将不胜感激。

【问题讨论】:

    标签: cakephp controller pagination paginator


    【解决方案1】:

    你的 index 函数应该有一个 paginate 函数,你应该给它 $posts 作为参数。

           public function index()
           {
               $posts = $this->Posts->find('all');
               $posts = $this->paginate($posts);
               $this->set(compact('posts'));
           }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-30
      • 2012-07-20
      • 2015-01-07
      • 1970-01-01
      • 2016-12-29
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多