php - 我不明白为什么会抛出“调用未定义的方法 CI_Input()::event()”
问题描述
我正在尝试使用表单将新记录(在这种情况下为事件)添加到数据库中。我不明白为什么我会收到以下错误:
这是我在控制器“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()
从我第一次尝试create_event()
分配$slug
值时尝试在函数中调用“事件”。
我知道在我试图引用它之前,我没有在创建函数中将“事件”初始化为对象(或方法?),但我只是试图从表单中获取值并将它们传递给数据库,
在我遵循的指南中,他们没有收到此类错误
任何帮助将不胜感激
解决方案
Input 类中没有event()
方法。你应该使用or方法。post()
get()
'title' => $this->input->post('title')
推荐阅读
- excel - 如何在 Excel 中自动重新创建空白表格
- sql - 使用由单独脚本生成的 ID 插入与外键约束冲突
- serial-port - 使用wireshark重新创建FTDI配置
- ldap - LDAPS 在 Samba 4.3.11-Ubuntu 中不起作用
- c# - 获取每个实体框架类的列表的通用方法
- php - 如何在 2 个数组中打印第一个 15 天和下一个 15 天的所有日期?
- python - 如何比较两个表的 id 以及当它们相等时在另一列中添加一个值
- iframe - 如果设置了 allow-same-origin,则 amp-iframe 的来源不得等于容器
- javascript - 以形状对齐的文本
- ios - 使用带有 SKShapenode 线的 PhysicsBody。斯威夫特,iOS,SpriteKit