0
我想使用getters/setters在我的Model.Below中存儲和檢索值是我的Controller和Model代碼。我想知道它是一個標準的正確方法來做到這一點?Codeigniter - 使用getters/setters將值從控制器傳遞到model
控制器代碼:
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();
}
MODEL CODE:
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();
}
}
感謝information.Its useful.They方式,我已經實現了是正確的? – Samy 2013-03-20 06:31:54
是的,這是正確的 – Shaolin 2013-03-20 06:32:47
@MDeSilva請不要讓人們標記/投票/接受你的答案。歡迎他們選擇如何在那裏行動,沒有任何壓力。 – 2013-03-20 10:45:17