我希望能够在不需要分页的情况下显示所有记录,但仍然希望通过使用类似$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>