2013-03-20 2 views
0

getter/setter를 사용하여 내 Model.Below에 값을 저장하고 검색하려면 컨트롤러 및 모델 코드를 사용하고 싶습니다. 나는 그것을 할 수있는 표준 올바른 방법을 알고 싶습니다?Codeigniter - getters/setters를 사용하여 컨트롤러에서 모델로 값 전달

컨트롤러 코드 :

public function saveevent() { 

    $this->event_model->setEvent_title($this->input->post('event_title')); 
    $this->event_model->setSms_description($this->input->post('sms_description')); 
    $event_id = $this->event_model->saveEvent(); 
} 

모델 코드 :

class Event_Model extends CI_Model{ 

private $id; 
private $event_title; 
private $sms_description; 

function __construct() { 
    parent::__construct(); 
} 

public function getId() { 
    return $this->id; 
} 

public function setId($id) { 
    $this->id = $id; 
} 

public function getEvent_title() { 
    return $this->event_title; 
} 

public function setEvent_title($event_title) { 
    $this->event_title = $event_title; 
} 

public function getSms_description() { 
    return $this->sms_description; 
} 

public function setSms_description($sms_description) { 
    $this->sms_description = $sms_description; 
} 

public function saveEvent() { 
    $data = array(
     'title' => $this->getEvent_title() , 
     'sms_description' => $this->getSms_description() 
    ); 

    $this->db->insert('events', $data); 
    return $this->db->insert_id(); 
} 
} 

답변

2

getter 및 setter 사용은 좋은 방법이지만, 그렇게 할 필요는 없습니다. 하지만 setter 및 getters를 계속 사용하는 것이 좋습니다.

내가 구현 한 information.Its useful.They의 방법을

Why use getters and setters? Getter and Setter?

+0

덕분에이 링크를 참조 맞습니까? – Samy

+0

예, 정확합니다. – Shaolin

+0

@MDeSilva 사람들에게 답을 표시/투표/수락하도록 요청하지 마십시오. 그들은 아무런 압력없이 그곳에서 행동하는 방법을 선택할 수 있습니다. –

관련 문제