我是 Codeigniter 的新手,并尝试从教程codeigniter login构建登录页面。现在,当我在输入用户名和密码后尝试登录时,出现以下错误。
遇到 PHP 错误
严重性:通知
消息:未定义的属性:Verifylogin::$form_validation
文件名:控制器/verifylogin.php
行号:18
编辑:
我的verifylogin.php
文件是
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Verifylogin extends CI_Controller
{
function __construct() {
parent::__construct();
}
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->model('user');
$this->load->library('form_validation');
//$this->load->library('form_validation', 'form_validation', true/false);
$this->form_validation->set_rules('username','Username','trim|required|xss_clean');
$this->form_validation->set_rules('password','Password','trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE)
{
redirect('login','refresh');
}
else
{
redirect('home','refresh');
}
}
function check_database($password)
{
$username = $this->input->post('username');
$this->load->model('user');
$result = $this->user->login($username,$password);
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array('id'=>$row->id,'username'=>$row->username);
$this->session->set_userdata('logged_in',$sess_array);
}
return TRUE;
}
else {
$this->form_validation->set_message('check_database','Invalid username or password');
}
}
}
?>
也是这个form_validation.php
文件所在的位置。