所以我正在尝试使用codeigniter验证器验证我的表单,它显示了这个奇怪的错误?
我已经自动加载了表单验证器库和帮助程序
$autoload['helper'] = array('url', 'form','text');
$autoload['libraries'] = array('form_validation', 'session');
那为什么会抛出未定义的属性? 这是我的控制器
<?php
class User extends CI_Controller
{
public function register()
{
//fields username,email,password1,password2
// $this->load->view('templates/header');
// $this->load->view('user/register');
$this->form_validation->set_rules('username','Username','required|max_length[50]|is_unique[users.username]|trim|alpha_numeric');
$this->form_valdiation->set_rules('email','Email', 'trim|required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('password1', 'Password', 'trim|required');
$this->form_validation->set_rules('password2','Confirm password','trim|required|matches[password1]');
if($this->validation->run === false)
{
$this->load->view('templates/header');
$this->load->view('user/register');
} else {
}
}
} 我究竟做错了什么?
答案 0 :(得分:2)
你在第二条规则中有一个拼写错误:
$this->form_valdiation->set_rules
必须是:form_validation
此外,您需要()来调用验证函数:
$this->form_validation->run()
希望它能解决。
答案 1 :(得分:0)
你有
$this->validation->run
尝试
if($this->form_validation->run() == false)
控制器https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
和
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
}