2014-04-04 2 views
0

나는 슬러그를 사용하여 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); 
     } 

내 모델. 고맙습니다.

+0

데이터베이스 라이브러리를로드 했습니까? –

+0

예. 있습니다. 나는 $ this-> load-> model (array ('mlogin', 'mhalaman'))과 같은 구조로 데이터베이스를로드한다. 그래서 뭐 할까? – user3459150

+0

'$ this-> db-> insert ($ this-> tbl_halaman, $ data)'를 반환 할 필요는 없습니다. 삽입 기능 사용에 대한 참조는 http://ellislab.com/codeigniter/user-guide/database/active_record.html을 참조하십시오. –

답변

0

$ this-> load-> database()를 모델 생성자에로드했는지 확인하십시오.

$ this-> db-> method_name(); 데이터베이스 라이브러리가로드 될 때만 작동합니다.

응용 프로그램에서 데이터베이스를 사용할 계획이라면/application/config /에있는 autoload.php에 추가하는 것이 좋습니다.

$ autoload [ 'libraries'] = array ('database');

+0

이미 확인하고로드되었습니다. – user3459150

+0

CI_Model을 확장 한 경우 다음의 Your_Model이 CI_Model을 확장하는지 확인할 수 있습니다. function __construct() { parent :: __ construct(); }} – user3470953

+0

예. 있습니다. 이 문제는 모달의 모든 데이터를 가져 오는 관계가 있습니까? 편집하고 코드를 보여주고 싶습니다. – user3459150

관련 문제