我无法在readHunters()
方法中插入pager
函数,这样表中的记录就不会都在同一页上(我想在每页上放置10条记录)。
我知道在app->Config->Pager.php
中有public $perPage = 10;
,它有助于定义表中分页的记录数。
HunterController.php
public function readHunters()
{
try {
$hunter = new HunterModel();
$data['hunter'] = $hunter->findAll();
$data['pager'] = $this->$hunter->page;
return view('read_hunters', $data);
} catch (\Exception $e) {
exit($e->getMessage());
}
}
read_hunters.php
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Year</th>
<th>Height</th>
<th>Weight</th>
<th>Type hunter</th>
<th>Type nen</th>
<th>Type blood</th>
<th>Date registration</th>
<th>Date upgrade</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($hunter as $hxh): ?>
<tr>
<td><?= $hxh['id_hunter']?></td>
<td><?= $hxh['name_hunter']?></td>
<td><?= $hxh['year_hunter']?></td>
<td><?= $hxh['height_hunter']?> m</td>
<td><?= $hxh['weight_hunter']?> kg</td>
<td><?= $hxh['type_hunter']?></td>
<td><?= $hxh['type_nen']?></td>
<td><?= $hxh['type_blood']?></td>
<td><?= date('d/m/Y H:i:s', strtotime($hxh['date_registration']))?></td>
<td><?= $hxh['date_update'] == $hxh['date_registration'] ? '' : date('d/m/Y H:i:s', strtotime($hxh['date_update'])) ?></td>
<td>
<a href="<?= site_url('form_update_hunter/'.$hxh['id_hunter']);?>" class="btn btn-primary">"><i class="fa fa-edit"></i> Update</a>
<a href="<?= site_url('delete_hunter/'.$hxh['id_hunter']);?>" class="btn btn-danger"><i class="fa fa-trash"></i> Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?= $pager->links(); ?>
1条答案
按热度按时间tgabmvqs1#
要在应用中提供分页列表,控制器的方法如下所示: