我为此项目使用CodeIgniter。在我的项目“ v_presensi_user_admin_awal”的第一页中,我必须显示一个名为“ user”的表。有“ no”代表数字,“ Detail”代表详细信息按钮,“ nama_user”代表用户名。单击详细信息按钮时,它应转到“ v_presensi_user”以显示我单击的用户的详细信息。但是它显示了一些错误。
A PHP Error was encountered
Severity: Notice
Message: Trying to get property 'nama_user' of non-object
Filename: views/v_presensi_user.php
Line Number: 26
Backtrace:
File: /var/www/html/bolehstation/myreport/application/views/v_presensi_user.php
Line: 26
Function: _error_handler
File: /var/www/html/bolehstation/myreport/application/views/template.php
Line: 183
Function: view
File: /var/www/html/bolehstation/myreport/application/controllers/Presensi_user.php
Line: 33
Function: view
File: /var/www/html/bolehstation/myreport/index.php
Line: 315
Function: require_once
以及其他详细信息的以下错误。 首先,控制器“ Presensi_user”显示“ v_presensi_user_admin_awal”:
public function index()
{
$data['konten']="v_presensi_user_admin_awal";
$this->load->model('presensi_m');
$data['data_presensi']=$this->presensi_m->get_pres_user_adm_awal();
$this->load->model('status_m');
$data['data_status']=$this->status_m->get_status();
$this->load->model('user_m');
$data['data_user']=$this->user_m->get_user();
$this->load->model('pengajar_m');
$data['data_pengajar']=$this->pengajar_m->get_pengajar();
$this->load->view('template', $data, FALSE);
}
在模型“ presensi_m”中,该方法获得方法“ get_pres_user_adm_awal”:
public function get_pres_user_adm_awal()
{
$data_presensi= $this->db
->join('user','user.id_user=presensi.id_user')
->join('status','status.id_status=presensi.id_status')
->join('pengajar','pengajar.id_pengajar=presensi.id_pengajar')
->get('presensi')->result();
return $data_presensi;
}
在“ v_presensi_user_admin_awal”中:
<table class="table table-hover table-striped">
<tr>
<th>NO</th>
<th>AKSI</th>
<th>NAMA SISWA</th>
</tr>
<?php
$no=0;
foreach ($data_user as $usr) {
$no++;
echo '<tr>
<td>'.$no.'</td>
<td>'.anchor('Presensi_user/detail/'.$usr->id_user,'<div class="btn btn-info">Detail</div>').'</td>
<td>'.$usr->nama_user.'</td>
</tr>';
}
?>
</table>
如果单击详细信息按钮,则它应继续执行控制器“ Presensi_user”中的“详细信息”方法:
public function detail($id_presensi)
{
$this->load->model('presensi_m');
$detail = $this->presensi_m->detail_data($id_presensi);
$data['detail'] = $detail;
$data['konten']="v_presensi_user";
$this->load->view('template', $data, FALSE);
}
在模型“ presensi_m”中称为方法“ detail_data”的方法:
public function detail_data($id_presensi = NULL)
{
$query = $this->db->where('id_presensi', $id_presensi)->get('presensi')->row();
return $query;
}
最后,它应该在视图“ v_presensi_user”中显示详细信息:
<table class="table table-hover table-striped">
<tr>
<th>NO</th>
<th>NAMA SISWA</th>
<th>NAMA PENGAJAR</th>
<th>HARI</th>
<th>DATANG</th>
<th>PULANG</th>
<th>STATUS</th>
</tr>
<?php
$no=0;
$no++;
echo '<tr>
<td>'.$no.'</td>
<td>'.$detail->nama_user.'</td>
<td>'.$detail->nama_pengajar.'</td>
<td>'.$detail->hari.'</td>
<td>'.$detail->datang.'</td>
<td>'.$detail->pulang.'</td>
<td>'.$detail->status.'</td>
</tr>'
?>
</table>
请帮助我解决此问题。我已经尝试并搜索了许多方法,但是找不到正确的方法。
答案 0 :(得分:0)
public function detail_data($id_presensi = NULL)
{
$this->db->select('*');
$this->db->from('presensi');
$this->db->where('id_presensi',$id_presensi);
$query = $this->db->get();
return $query->result();
}
public function detail($id_presensi)
{
$this->load->model('presensi_m');
$data['detail'] = $this->presensi_m->detail_data($id_presensi);
$data['konten']="v_presensi_user";
$this->load->view('template', $data);
}