我试图找出为什么我的$id仍然为NULL,但在另一个项目中它有效请帮我查找错误
An uncaught Exception was encountered
Type: Error
> Message: Call to a member function get_pengajuan() on null
Filename: .magangapplicationcontrollersSurat.php
Line Number: 40
Backtrace:
File: .magangindex.php
Line: 315
Function: require_once
第40行为$data['pengajuan'] = $this->MPengajuan->get_pengajuan($id);
控制器:
public function edit($id)
{
$this->load->view("header");
$this->load->view("home/user");
$this->load->view("home/admin");
$this->load->view("topbar");
$this->load->view("admin/edit_surat");
$this->load->view("footer");
$data['pengajuan'] = $this->MPengajuan->get_pengajuan($id);
}
型号:
public function get_pengajuan($id) {
$query = $this->db->query("SELECT pengajuan.* , instansi_magang.nama_instansi FROM pengajuan,instansi_magang WHERE pengajuan.id_instansi=instansi_magang.id_instansi AND id_pengajuan='$id'");
return $query->result_array();
}
视图:
<?php
foreach ($pengajuan as $pengajuan_item){
echo form_open_multipart('Surat/edit/'.$pengajuan_item['id_pengajuan']);
}
?>
我建议您的错误是:
-
您不必使用
form_open_multipart
。因为没有要上传的文件。 -
您的控制器在视图中必须使用小写
('surat/edit/'.$pengajuan_item['id_pengajuan'])
我得到了解决方案我忘了用加载构建中的模型
$this->load->model('MPengajuan');