【发布时间】:2019-02-14 13:48:06
【问题描述】:
在视图方法中,我从数据库中下载了所有与课程表相关的学生,并添加了分页。
$this->paginate = [
'order' => ['id' => 'desc'],
'conditions' => ['Students.course_id =' => $id]
];
$students = $this->paginate($this->Students);
$this->set(compact('students'));
在视图 (view.ctp) 中,我通过 foreach 显示了整个表格。在第一列中,我希望显示订单号。我试过用foreach用$键,但是如果我去另一边,数字归零,我不能用ID。
<?php foreach ($students as $key => $student): ?>
<tr>
<td><?= h($key) ?></td>
想要这样的东西:
第 1 页
|------------|-----------|---------------|
| LP | ID | NAME |
|------------|-----------|---------------|
| 1 | 5437 | Mark |
|------------|-----------|---------------|
| 2 | 67 | John |
|------------|-----------|---------------|
| 3 | 12 | Lisa |
|------------|-----------|---------------|
| 4 | 63 | John |
|------------|-----------|---------------|
| 5 | 657 | Lisa |
|------------|-----------|---------------|
第 2 页
|------------|-----------|---------------|
| LP | ID | NAME |
|------------|-----------|---------------|
| 6 | 5431 | Michael |
|------------|-----------|---------------|
| 7 | 36554 | Lara |
|------------|-----------|---------------|
| 8 | 99 | Anne |
|------------|-----------|---------------|
| 9 | 76 | Luke |
|------------|-----------|---------------|
| 10 | 351 | Chris |
|------------|-----------|---------------|
【问题讨论】:
标签: php mysql cakephp pagination cakephp-3.x