我試圖將驗證規則從控制器移動到配置文件中。我按照文件here的說明,但我無法讓它工作。提交表單時,驗證不會執行。回聲validation_errors()
什麼都不打印。將驗證規則保存到配置文件的問題
做一個小挖之後,在表單驗證庫run()
方法返回假因爲有沒有設定的配置規則。下面是摘錄:
系統/庫/ Form_validation.php:
// No validation rules? We're done...
if (count($this->_config_rules) == 0)
{
return FALSE;
}
任何幫助,將不勝感激。這裏是我的代碼:
應用/控制器/ signup.php:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Signup extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
if ($this->form_validation->run()) {
$this->user_model->insert(array(
'email_address' => $this->input->post('email_address'),
'password' => $this->input->post('password'),
));
redirect('/log-in');
}
$this->load->view('header');
$this->load->view('signup/index');
$this->load->view('footer');
}
}
/* End of file signup.php */
/* Location: ./application/controllers/signup.php */
的application/config/form_validation.php:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'signup/index' => array(
array(
'field' => 'email_address',
'label' => 'Email Address',
'rules' => 'trim|required|max_length[255]|valid_email|email_in_use'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'required|min_length[6]'
),
array(
'field' => 'confirm_password',
'label' => 'Confirm Password',
'rules' => 'required|matches[password]'
),
),
);
/* End of file form_validation.php */
/* Location: ./application/config/form_validation.php */
我使用CI 2.1.0 。
我得到了相同的親......這是一bug? – zhkzyth 2014-08-20 17:28:33
它看起來像有人面臨相同的專業人士如您可以找到一些解決方案在這[鏈接](http://stackoverflow.com/questions/14179936/custom-config-file-not-working-withform -validation?rq = 1) – zhkzyth 2014-08-20 17:35:49