2012-06-19 2 views
0

컨트롤러와 모델이 있습니다. 모델의 변수 값을 수정하고 있지만 컨트롤러에 반영되지는 않지만 OOP에서는 많은 전문가가 아닙니다.코드 명 모델에서 변수 값 수정

// controller class structure 
class Leads_import extends CI_Controller { 

public $total = 0; 

    public function import(){ 
    $this->xml_model->imsert(); 
    echo $this->total; 
    } 
} 

// model class structure 
class xml_model extends CI_Model { 

    public function insert(){ 
     this->total = 10; 
    } 
} 

답변

0

이 시도 :

// controller class structure 
class Leads_import extends CI_Controller { 

public $total = 0; 

    public function import(){ 
    $this->total = $this->xml_model->imsert(); 
    } 
} 

모델 :

// model class structure 
class xml_model extends CI_Model { 

    public function insert(){ 
     return 10; 
    } 
} 
+0

감사하지만 난 기능과 ​​그 funciton에서 뭔가를 돌려 질수 있도록 "삽입"다른 일을 수행하고있다 : 여기

당신이 정말로 뭘 하려는지 알지 못하고 내가 제안 무엇 삽입 함수가 많은 일을하기 때문에이 줄을 "$ this-> total = $ this-> xml_model-> insert()"라고 쓰십시오. 이해가 안되면 알려 주시기 바랍니다. –

0

을 당신은 $totalxml_model의를 확인하거나가 $totalLeads_import의를 업데이트해야합니다. 컨트롤러에서 잘못된 변수를 읽고 있습니다. 결코 업데이트되지 않습니다. 도움을

class Leads_import extends CI_Controller { 
    public $total = 0; 
    public function import(){ 
    $this->xml_model->insert(); 
    // Read xml_model total and assign to Leads_import total 
    $this->total = $this->xml_model->total; 
    echo $this->total; 
    } 
} 

class xml_model extends CI_Model { 
    public $total = 0; 
    public function insert(){ 
     $this->total = 10; // update xml_model total 
    } 
}