나는 슬러그를 사용하여 codeigniter에서 뉴스 항목을 만들고 싶지만 이렇게 오류 표시가됩니다.codeigniter에서 뉴스 항목 만들기
> Call to a member function insert() on a non-object in line 34
저는 Codeigniter의 초보자이며이를 해결하는 방법을 실제로 알 수 없습니다.
내 컨트롤러
var $db;
private $tbl_halaman = 'halaman';
public function __construct()
{
parent ::__construct();
$this->load->database();
}
function get_profil($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get($this->tbl_halaman);
return $query->result_array();
}
$query = $this->db->get_where($this->tbl_halaman, array('slug'=>$slug));
return $query->row_array();
}
function insert_profil()
{
$slug = url_title($this->input->post('judul'),'dash', TRUE);
$data = array(
'judul' => $this->input->post('judul'),
'slug' => $slug,
'content' => $this->input->post('content')
);
return $this->db->insert($this->tbl_halaman ,$data); //line 34
}
가 무엇을 저를 도와주세요
function tambah_profil()
{
$this->data['title'] ='create a new items';
$this->form_validation->set_rules('judul', 'Judul', 'required');
$this->form_validation->set_rules('content', 'Content', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->data['contents'] = $this->load->view('admin/profil/tambah_profil', '', true);
}else{
$this->mhalaman->insert_profil();
$this->data['contents'] = $this->load->view('admin/profil/view_profil', '', true);
}
$this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
$this->data['contents'] = $this->load->view('admin/profil/tambah_profil', '', true);
//$this->data['contents'] = 'admin/profil/tambah_profil';
$this->load->view('template/wrapper/admin/wrapper_ukm',$this->data);
}
내 모델. 고맙습니다.
데이터베이스 라이브러리를로드 했습니까? –
예. 있습니다. 나는 $ this-> load-> model (array ('mlogin', 'mhalaman'))과 같은 구조로 데이터베이스를로드한다. 그래서 뭐 할까? – user3459150
'$ this-> db-> insert ($ this-> tbl_halaman, $ data)'를 반환 할 필요는 없습니다. 삽입 기능 사용에 대한 참조는 http://ellislab.com/codeigniter/user-guide/database/active_record.html을 참조하십시오. –