每次我更新我的设置并将输入 type="file" 留空。$this->form_validation->run() 总是返回 false。我什至没有使用 setrules 并且需要它。
这是我的代码:
public function update_settings()
{
$this->load->model('bus_owner_model');
$data = $this->bus_owner_model->get_business_data_id_by_row($this->session->userdata('id'));
$this->load->library('form_validation');
$this->form_validation->set_rules('business_name', 'Business Name', 'required|trim|xss_clean');
$this->form_validation->set_rules('type_of_business', 'Type of Business', 'required|trim');
$this->form_validation->set_rules('country', 'Country', 'required|trim');
$this->form_validation->set_rules('address', 'Address', 'required|trim');
$this->form_validation->set_rules('city', 'City', 'required|trim|alpha');
$this->form_validation->set_rules('email_address', 'Email Address', 'required|trim|valid_email');
$this->form_validation->set_rules('contact', 'Contact', 'required|trim|numeric|min_length[7]');
$this->form_validation->set_message('is_unique', 'Your email address is already been taken');
if($this->form_validation->run() == true)
{
$config['upload_path'] = "./_profile_images/";
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['encrypt_name'] = "true";
$this->load->library('upload', $config);
if(!$this->upload->do_upload())
{
$this->bus_settings($this->upload->display_errors());
}else
{
$this->load->model('bus_owner_model');
$file_data = $this->upload->data();
$data = array(
'company_name' => $this->input->post('business_name'),
'profile_img' => $file_data['file_name'],
'type_description' => $this->input->post('type_of_business'),
'country' => $this->input->post('country'),
'address' => $this->input->post('address'),
'state' => $this->input->post('state'),
'city' => $this->input->post('city'),
'email_address_c' => $this->input->post('email_address'),
'contact' => $this->input->post('contact')
);
if($this->bus_owner_model->update_bus($data) == true)
{
redirect('bus_owner/bus_settings');
}else
{
$this->load->model('bus_owner_model');
$this->load->model('user_model');
$data['latlng'] = $this->bus_owner_model->get_latlng();
$data['get_all_business_data_orderby_total_result'] = $this->bus_owner_model->get_all_business_data_orderby_total();
$data['get_all_user_data_orderby_total_result'] = $this->user_model->get_all_user_data_orderby_total();
$data['result_countries'] = $this->bus_owner_model->get_countries();
$data['get_business_data_result'] = $this->bus_owner_model->get_business_data();
$data = array('error' => 'unable to upload files');
$this->load->view('site_header', $data);
$this->load->view('bus_owner_views/left_col_map_single');
$this->load->view('left_col_static', $data);
$this->load->view('bus_owner_views/right_col_settings', $data);
$this->load->view('site_footer');
}
}
}
}
然后它会返回到它的页面并且什么都没有发生。