编码点火器中的分页不起作用 - 无法转换为字符串



我无法在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>&nbsp;Update</a>
&nbsp;
<a href="<?= site_url('delete_hunter/'.$hxh['id_hunter']);?>" class="btn btn-danger"><i class="fa fa-trash"></i>&nbsp;Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?= $pager->links(); ?>

要在应用程序中提供分页列表,控制器的方法如下:

$data = [
'hunter' => $hunter->paginate(10),
'pager' => $hunter->pager,
];
return view('read_hunters', $data);

相关内容

  • 没有找到相关文章