可能我错过了一些东西。我环顾网络,SO寻找答案,但一无所获。这是我的问题:我正在__construct
方法中加载form_validation
库,但 PHP 仍然抱怨validation_errors
方法未定义。此外form
助手是自动加载的。
...
...
function __construct()
{
parent::__construct();
$this->load->library('ion_auth');
$this->load->library('form_validation');
$this->load->helper('url');
....
....
function login()
{
$this->data['title'] = "Login";
.....
.....
//the user is not logging in so display the login page
//set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
在上面的最后一行抛出错误。(此代码是ion_auth模块 http://benedmunds.com/ion_auth/的一部分)
你可以试试这个:
$this->data['message'] = ($this->form_validation->run() == False) ? validation_errors() : $this->session->flashdata('message');
此外,请确保在调用 validation_errors()
帮助程序函数之前已加载helper (form_helper.php)
因为此帮助程序文件中提供了此函数。要加载帮助程序文件,您可以使用:
$this->load->helper('form');
你应该调用form_validation类的 run() 方法。此外,您还应该定义表单变量。
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
if ($this->form_validation->run() == FALSE)
$this->data['message'] = $this->session->flashdata('message');