我有一个控制器:
AnotherClass.fxml
当我发布表单时,我收到此错误:
致命错误:在第450行的 ... \ libraries \ Form_validation.php 中调用未定义的方法stdClass :: load()
if($_POST) {
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$val = $this->form_validation;
$val->set_rules('content[title]', 'Title', 'trim|required');
$val->set_rules('content[subtitle]', 'Subtitle', 'trim');
$val->set_rules('content[description]', 'description', 'trim');
if ($val->run() AND $this->db->insert('content', $content)) {
// query done
}
}
Form_validation.php
请帮我解决这个问题....
答案 0 :(得分:1)
将您的input names
替换为标题,副标题,说明并尝试使用此代码
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
if ($this->input->post()) {
$this->form_validation->set_rules('title', 'Title', 'trim|required');
$this->form_validation->set_rules('subtitle', 'Subtitle', 'trim');
$this->form_validation->set_rules('title', 'Description', 'required');
$data['content'] = array(
'db_field_name' => $this->input->post('title'),
'db_field_name' => $this->input->post('subtitle'),
'db_field_name' => $this->input->post('description'),
);
if ($this->form_validation->run()){
$this->db->insert('content', $data['content']);
}
}
答案 1 :(得分:0)
如果您使用表单验证并且所有用于多个实例,则可以在config / autoload.php中定义帮助程序和库。另请参阅input_field名称以获取验证规则。
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
if ($this->input->post()) {
$this->form_validation->set_rules('title', 'Title', 'trim|required');
$this->form_validation->set_rules('subtitle', 'Subtitle', 'trim');
$this->form_validation->set_rules('title', 'Description', 'required');
if ($this->form_validation->run() == TRUE) {
//Your DB operation
$this->data['formdata'] = array(
'db_field_title' => $this->input->post('title'),
'db_field_subtitle' => $this->input->post('subtitle'),
'db_field_description' => $this->input->post('description')
);
$this->db->insert('content', $this->data['content']);
} else {
//Show error message
echo validation_errors();
}
}
答案 2 :(得分:0)
在你的情况下,我认为缺少语言文件
您必须在 system / language / english文件夹中检查是否有form_validation_lang.php可用。缺少form_Validation_lang.php,您必须放置该文件