我试图使用一个表单向数据库中添加一条新记录,在这种情况下,是为了一个事件。我不明白为什么我会收到以下错误信息。
这是我在控制器中的create函数,'Events.php':
public function create(){
$data['title'] = 'Create Event';
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('description', 'Description', 'required');
$this->form_validation->set_rules('location', 'Location', 'required');
$this->form_validation->set_rules('date', 'Date', 'required');
$this->form_validation->set_rules('time', 'Time', 'required');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('events/create', $data);
$this->load->view('templates/footer');
} else {
$this->Event_model->create_event();
redirect('events');
}
}
然后是我在 "Event_model "中的create_event函数 来尝试创建一个新的条目对象(?) 然后将其添加到数据库中:
public function create_event(){
$slug = url_title($this->input->event('title'));
$data = array(
'title' => $this->input->event('title'),
'description' => $this->input->event('description'),
'date' => $this->input->event('date'),
'time' => $this->input->event('time'),
'location' => $this->input->event('location'),
'slug' => $slug,
'invitees' => $this->input->event('invitees')
);
return $this->db->insert('events', $data);
}
我得到的错误是:
Message: Call to undefined method CI_Input::event()
从我第一次尝试调用'event'函数的时候开始,我就得到了一个错误信息 create_event()
函数时,我试图将 $slug
值。
我知道在我试图引用'event'之前,我没有在create函数中初始化'event'为一个对象(或方法),但我只是试图从表单中获取值并将其传递给数据库。
在我所遵循的指南中,他们没有收到这样的错误。
衷心感谢您的帮助
没有 event()
方法中 输入类. 你应该使用 post()
或 get()
方法;
'title' => $this->input->post('title')