codeigniter中的分页不起作用-无法转换为字符串

rjjhvcjd  于 2022-12-16  发布在  其他
关注(0)|答案(1)|浏览(144)

我无法在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(); ?>
tgabmvqs

tgabmvqs1#

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

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

return view('read_hunters', $data);

相关问题