嗨,我正在尝试使用代码点火器正确分页,但似乎它不想正常工作。我得到了第二页,但分页消失了,但我仍然得到了正确的表格,但我有 2 个错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: models/evaluation_model.php
Line Number: 37
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/evaluation_model.php
Line Number: 37
控制器功能:
function showEvaluations($offset = 0)
{
if($this->login->is_logged_in())
{
$limit = 5;
$result = $this->evaluation_model->getAllEvaluations($limit, $offset);
if ($this->session->userdata('type') == 'admin')
{
$data['evaluations'] = $result['evaluations'];
$data['total'] = $result['num_rows'];
$data['notallowed'] = false;
$config = array();
$config['base_url'] = base_url("evaluation/showEvaluations/");
$config['total_rows'] = $data['total'];
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('allevaluations_view', $data);
}
else
{
$data['notallowed'] = true;
$this->load->view('allevaluations_view', $data);
}
//$this->load->view('allevaluations_view', $data);
}
else
{
$this->load->view('login_view');
}
}
和模型:
function getAllEvaluations($limit, $offset)
{
$q = $this->db->select('tblPunten.PK_PuntID, tblPunten.Titel, tblPunten.Score, tblVakken.Vak, tblUsers.username, tblUsers.Voornaam, tblUsers.Achternaam')
->from('tblPunten')
->join('tblVakken', 'tblPunten.FK_VakID = tblVakken.PK_VakID')
->join('tblUsers', 'tblPunten.FK_UserID = tblUsers.PK_UserID')
->limit($limit, $offset);
$query['evaluations'] = $q->get()->result();
$q = $this->db->select('COUNT(*) as count', FALSE)
->from('tblPunten')
->limit($limit, $offset);
$tmp = $q->get()->result();
$query['num_rows'] = $tmp[0]->count;
return $query;
}
第 37 行: $query['num_rows'] = $tmp[0]->count;