【发布时间】:2012-10-28 21:09:35
【问题描述】:
我希望能够在不需要分页的情况下显示所有记录,但仍希望通过使用 $this->Paginator->sort() 之类的东西来保留具有可排序列标题的功能。
目前我正在设置'limit' => 100,因为我知道我一次不会有超过 50 条记录,这很好用,但是我想知道是否有基本的方法来完成可排序没有分页的列以其他方式,例如 'limit' => unlimited 或其他可以实现此目的的 CakePHP 组件。
这是控制器:
class GroupsController extends AppController {
public function view($slug = null) {
$group = $this->Group->findBySlug($slug);
$this->paginate = array(
'Person' => array(
'conditions' => array('Person.group_id' => $group["Group"]['id']),
'limit' => 100,
'recursive' => 0
)
);
$people = $this->paginate('Person');
$this->set('people', $people);
}
}
这是视图:
<table>
<tr>
<th><?php echo $this->Paginator->sort('Person.id','Id'); ?></th>
<th><?php echo $this->Paginator->sort('first_name', 'First Name'); ?></th>
<th><?php echo $this->Paginator->sort('last_name', 'Last Name'); ?></th>
</tr>
<!-- Here is where we loop through the people -->
<?php foreach ($people as $person): ?>
<tr>
<td><?php echo $person['Person']['id']; ?></td>
<td><?php echo $person['Person']['first_name']; ?></td>
<td><?php echo $person['Person']['last_name']; ?></td>
</tr>
<?php endforeach; ?>
<?php unset($player); ?>
</table>
【问题讨论】:
-
我同意@RichardAtHome - 没有理由不使用 Paginator - 如果您不想要页面,只需将限制设置为无法访问的数字。
标签: cakephp cakephp-2.0 cakephp-2.1