【发布时间】: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