2012-11-02 4 views
1

저는 CI가 처음인데 mysql의 일부 데이터를 업데이트하려고합니다. 그래서 여기 내 컨트롤러Codeigniter 컨트롤러 모델 호출이 실패했습니다.

class Ci_update extends CI_Controller 
{ 
    function __construct() { 
     parent::__construct(); 
    } 

    function index() 
    { 
     $data = array 
     (
      'title' => 'Data Structure using C', 
      'text' => 'Data Structure Using C, for, IIIrd Sem VTU CSE students' 
     ); 
     $id = 4 ; 

     $this->load->model('ci_update_model'); 
     $this->ci_update_model($data,$id); 
    } 
} 

하고 내 모델은 다음과 같습니다

class Ci_update_model extends CI_Model 
{ 
    function __construct() { 
     parent::__construct(); 
    } 

    function updateData($data,$id) 
    { 
     $this->db->where('id',$id); 
     $this->db->update('data',$data); 
    } 
} 

하지만이 프로그램을 실행하려고 할 때, 그것은 wrom 내가 뭘 Call to undefined method Ci_update::ci_update_model() in C:\wamp\www\ci\application\controllers\ci_update.php on line 19 말한다? 컨트롤러의 constructer에서

+0

요 $ this-> ci_update_model-> function ($ var) ... $ this-> ci_update_model ($ var) ...이 경우 함수 ci_update_model을 검색하고 있습니다. 컨트롤러 클래스 내부에서 .. – Svetoslav

답변

6

를 사용하여 해결 얻을 것이다, 나머지는 동일합니다 :

$this->load->model('ci_update_model'); 
$this->ci_update_model->updateData($data,$id); 
-3

이 줄

$this->load->model('Ci_update_model'); 

을 추가하고 오류가

$this->load->model('ci_update_model'); 
$this->ci_update_model->updateData($data,$id); 
+0

생성자에서 모델을로드하면 컨트롤러 파일의 나머지 기능에서 모델을로드 할 필요가 없습니다. 그래서 당신이 가지고있는 모든 함수에서'$ this-> load-> model ('Ci_update_model');을 사용하지 않으려면 생성자 자체에서 모델을로드하는 것이 좋습니다. –

+0

문제는 모델을로드 할 때 문제가 아니며, 내부에서 함수를 호출 할 때 발생합니다. 그리고 컨트롤러에 하나의 컨트롤러 함수가 필요한 경우 (생성자에서 모든 것을로드해야하는 이유)? – Svetoslav

+0

CI에서 우리는 인덱스 함수와 함께 몇 가지 다른 함수를 사용합니다. –

0

이 당신의 컨트롤러 코드에서 변경 DO 아래로

관련 문제