Php CodeIgniter登录脚本的帮助

Php CodeIgniter登录脚本的帮助,php,codeigniter,Php,Codeigniter,我发现这行有一个错误: $result = $this->user->login($username, $password); 对未定义的方法或对象进行调用 控制器: <?php if (! defined('BASEPATH')) exit(' No direct script access allowed'); class verifyLogin extends CI_Controller{ function _contruct() {

我发现这行有一个错误:

$result = $this->user->login($username, $password);
对未定义的方法或对象进行调用

控制器:

<?php if (! defined('BASEPATH')) exit(' No direct script access allowed');

class verifyLogin extends CI_Controller{

    function _contruct()
    {
        parent::_construct();
        $this->load->model('User','',TRUE);

    }

    function index()
    {
        //validate the credentials
        $this->load->library('form_validation');

        $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)
        {
            //if validation fails then redirect to login page
            $this->load->view('login_view');
        }
            else
            {
                //go to private area
                redirect('home', 'refresh');
            }
    }

    function check_database($password)
    {

        //validate against database 
        $username = $this->input->post('username');

        //query the database
        $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');
                return false;
                }
            }
}

?>

型号:

<?php
class User extends CI_Model
{
    function login($username, $password)
    {
        $this-> db -> select('id, username, password');
        $this-> db -> from('users');
        $this-> db -> where('username = ' . "'" . $username . "'");
        $this-> db -> where('password = ' . "'" . MD5($password) . "'");
        $this-> db -> limit(1);

        $query = $this -> db -> get();

        if($query -> num_rows() == 1)
        {
            return $query->result();
        }
            else
            {
                return false;
            }

    }
}

?>

在代码“\u construct”而不是“construct”中,构造函数函数名拼写错误

在代码“\u construct”而不是“construct”中,构造函数函数名拼写错误

如果是
$this->User->login
,是否需要实例化模型??替换
$this->load->model('User','',TRUE)使用此
$this->load->model('User')。Model loader函数指定的有效名称中的第二个参数。例如,如果第二个参数是
test
,那么可以通过
$this->test
访问模型,我注意到这个示例;Blogmodel类扩展了CI_模型{…也调用构造函数。确切的错误是未定义属性:verifyLogin::$userI正在运行xampp它可能与php.ini中的设置有关吗?或者与CI的配置有关吗?如果是
$this->User->login
,是否需要实例化模型??替换
$this->load->Model('User','',TRUE)
使用this
$this->load->model('User');
。model loader函数是您指定的有效名称中的第二个参数。例如,如果第二个参数是
test
,则可以通过
$this->test
访问模型。我注意到示例;class Blogmodel扩展了CI_model{…还调用构造函数。确切的错误是未定义属性:verifyLogin::$userI正在运行xampp可能与php.ini中的设置或CI的配置有关吗?确定我移动了加载用户模型以检查数据库功能,但现在当信息在数据库中时,它给了我无效的用户名或密码。确定我移动了加载用户模型检查数据库功能,但现在它给我无效的用户名或密码时,信息是在数据库中。