无法访问与您的字段名称“结束日期”对应的错误消息.() 在 CodeIgniter 中


Unable to access an error message corresponding to your field name End Date.() in CodeIgniter

我收到这些消息

无法访问与您的字段名称对应的错误消息 子参考编号()
无法访问与您的字段名称"结束日期"对应的错误消息。() 当我尝试将数据传递到模型中时。

控制器

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class create_handler extends CI_Controller {
public function __construct() {
    parent:: __construct();
    $this->load->library('session');
    $this->load->helper('form');
    $this->load->helper('url');
    $this->load->helper('security');
    $this->load->database();
    $this->load->library('form_validation');
    //load the create_crpo model
    $this->load->model('mcreate_crpo');
}
function index() {
    $data = '';
    $this->form_validation->set_rules('officer_no', 'Officer Identification Number', 'trim|required');
    $this->form_validation->set_rules('child_ref', 'Child Reference no', 'trim|required|');
    $this->form_validation->set_rules('start_date', 'Start Date', 'trim|required');
    $this->form_validation->set_rules('end_date', 'End Date', 'trim|required|');
    if ($this->form_validation->run() == FALSE) {
        $this->load->view('header');
        $this->load->view('create_handler_view', $data);
        $this->load->view('footer');
    } else {
        //validation okay
        $officer_no = $this->input->post('officer_no', TRUE);
        $child_no = $this->input->post('child_ref', TRUE);
        $start_date = $this->input->post('start_date', TRUE);
        $end_date = $this->input->post('end_date', TRUE);
        $array1 = array(
            'ChildId' => $child_no,
            'CRPOId' => $officer_no,
            'start_date' => $start_date,
            'end_date' => $end_date
        );
        $insert_to_handler = $this->user_model->create_users('handler', $array1);
        if (!empty($insert_to_handler)) {
            // user creation ok
            $this->session->set_flashdata('msg', '<div class="alert alert-success text-center">Handler details are added to Database !!!</div>');
            $this->load->view('header');
            $this->load->view('create_handler_view');
            $this->load->view('footer');
        } else {
            // user creation failed
            $data->error = 'There was a problem creating the new account. Please try again.';
            // send error to the view
            $this->load->view('header');
            $this->load->view('create_handler_view', $data);
            $this->load->view('footer');
        }
    }
}
}
?>

你有没有加载过你的user_model?

将模型载荷添加到 __construct() 的末尾。

$this->load->model('user_model');

另外,如前所述,删除尾随 |'s 来自验证。

此外,var_dump($array 1); 进行测试以确保数据正确。

从规则中删除结束管道。

$this->form_validation->set_rules('officer_no', 'Officer Identification Number', 'trim|required');
$this->form_validation->set_rules('child_ref', 'Child Reference no', 'trim|required');
$this->form_validation->set_rules('start_date', 'Start Date', 'trim|required');
$this->form_validation->set_rules('end_date', 'End Date', 'trim|required');