こんにちは、コード イグナイターを使用してページネーションを正しく設定しようとしていますが、正しく動作しないようです。私は2番目のページを取得しますが、そこでページネーションが消えます.それでも正しいテーブルを取得していますが、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;