我正在使用Codeigniter ..而且我是新手。我试图做的是在我的代码中使用分页,但问题是分页链接没有显示在底部。
我的控制器:
public function dsbds()
{
$this->load->library('pagination');
$this->load->model('admin_model');
$result_per_page = 1; // the number of result per page
$config['base_url'] = base_url() . '/admin/';
$config['total_rows'] = $this->admin_model->dsbds();
$config['per_page'] = $result_per_page;
$this->pagination->initialize($config);
$datatable = $this->admin_model->dsbds($result_per_page, $this->uri->segment(3));
$this->load->view('admin/danhsachbds', array(
'bds' => $datatable,
'result_per_page' => $result_per_page
));
}
我的模特:
public function dsbds($limit, $offset)
{
$this->db->limit($limit, $offset);
$q = $this->db->query("SELECT bds.id, duan.tenduan, loaibds.loai, bds.tieude, phongngu.phongngu, phongtam.phongtam, viewbds.view, huongbds.huong, noithat.noithat, bds.dientich, bds.gia, donvibds.donvi, bds.noidung, duan.slugda, bds.slugbds, bds.datecreate, bds.dateupdate FROM bds LEFT JOIN duan ON duan.id=bds.tenduan LEFT JOIN loaibds ON loaibds.id=bds.loai LEFT JOIN phongngu ON phongngu.id=bds.phongngu LEFT JOIN phongtam ON phongtam.id=bds.phongtam LEFT JOIN viewbds ON viewbds.id=bds.view LEFT JOIN huongbds ON huongbds.id=bds.huong LEFT JOIN noithat ON noithat.id=bds.noithat LEFT JOIN donvibds ON donvibds.id=bds.donvi ORDER BY bds.id DESC");
if($q->num_rows() > 0)
return $q->result();
return false;
}
我的观点:
<table>
<tbody>
<?php foreach($bds as $d) { ?>
<tr>
<td><?php echo $d->id; ?></td>
<td><?php echo $d->tenduan; ?></td>
<td><?php echo $d->phongngu; ?></td>
<td><?php echo $d->phongtam; ?></td>
<td><?php echo $d->dientich; ?></td>
<td><?php echo $d->noithat; ?></td>
<td><?php echo $d->gia; ?> <?php echo $d->donvi; ?></td>
<td><button type="button" class="btn btn-success btn-sm">Edit</button> </td>
</tr>
<?php } ?>
</tbody>
<?php echo $this->pagination->create_links(); ?>
</table>
我的错误:
严重性:警告 消息:缺少Admin_Model :: dsbds()的参数1,在第231行的/application/controllers/admin.php中调用并定义 文件名:models / admin_model.php
严重性:警告 消息:缺少Admin_Model :: dsbds()的参数2,在第231行的/application/controllers/admin.php中调用并定义 文件名:models / admin_model.php
遇到PHP错误 严重性:注意 消息:未定义的变量:限制 文件名:models / admin_model.php 行号:316
遇到PHP错误 严重性:注意 消息:未定义的变量:偏移量 文件名:models / admin_model.php 行号:316
致命错误:第124行/ code/system/libraries/Pagination.php中不支持的操作数类型
答案 0 :(得分:0)
首先,$ result_per_page未在控制器功能中定义。你应该在函数内定义它。在您的情况下,$ this-&gt; uri-&gt; segment(3)似乎也不存在。您正在尝试的页面网址是什么。您应该再次计算网址细分。好吧,我相信你正在测试第一页,在这种情况下它没有分页段(第3页)。