我在CodeIgniter框架中遇到问题,
控制器:
public function tambah() {
$this->form_validation->set_rules('judul', 'Judul', 'required');
$this->form_validation->set_rules('deskripsi', 'Deskripsi','required');
$this->form_validation->set_rules('isi', 'Isi', 'required');
if ($this->form_validation->run() === FALSE) {
$data=array('title'=>'Menambah Berita',
'isi' =>'admin/berita/tambah_berita'
);
$this->load->view('admin/layout/wrapper',$data);
}else{
$tag = url_title($this->input->post('judul'), 'dash', TRUE);
$data = array(
'judul' => $this->input->post('judul'),
'tag' => $tag,//edited
'deskripsi' => $this->input->post('deskripsi'),
'isi' => $this->input->post('isi'),
'status' => $this->input->post('status'),
'id_admin' => $this->input->post('id_admin')
);
$this->berita_model->tambah($data);
redirect(base_url().'admin/berita/');
} }
型号:
public function tambah($data) {
return $this->db->insert('lm_destination', $data);
}
查看:视图文件已修复。
那些代码产生:
致命错误:在第41行调用C:。\ application \ controllers \ admin \ file.php中的未定义方法Berita_model :: tambah()
有人可以帮我解决吗?感谢
答案 0 :(得分:1)
你必须写
$this->load->model('berita_model');
使用前
$this->berita_model->tambah($data);
答案 1 :(得分:0)
我希望这会对你有所帮助
控制器:
public function tambah() {
$this->form_validation->set_rules('judul', 'Judul', 'required');
$this->form_validation->set_rules('deskripsi', 'Deskripsi','required');
$this->form_validation->set_rules('isi', 'Isi', 'required');
if ($this->form_validation->run() === FALSE) {
$data=array('title'=>'Menambah Berita',
'isi' =>'admin/berita/tambah_berita'
);
$this->load->view('admin/layout/wrapper',$data);
}else{
$tag = url_title($this->input->post('judul'), 'dash', TRUE);
$data = array(
'judul' => $this->input->post('judul'),
'tag' => $tag,//edited
'deskripsi' => $this->input->post('deskripsi'),
'isi' => $this->input->post('isi'),
'status' => $this->input->post('status'),
'id_admin' => $this->input->post('id_admin')
);
$this->load->model('berita_model');
$this->berita_model->tambah($data);
redirect(base_url().'admin/berita/');
} }
型号:
public function tambah($data) {
$this->db->insert('lm_destination', $data);
return true;
}