代码点火器模型未正确加载


CodeIgniter model not loading correctly

我正在编写我的第一个 CodeIgniter 脚本,如果有人可以帮助我,我无法加载以下模型?

这是我的控制器文件:

public function process(){
// Load the model
$this->load->model('users/login', 'users');
// Validate the user can login
$result = $this->users->validate();
// Now we verify the result
if(!$result){
    // If user did not validate, then show them login page again
    $this->index();
}else{
    // If user did validate,
    // Send them to members area
    redirect('home');
}      
}

这是我的模型

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

class Login_Model extends CI_Model{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    public function validate(){
        // grab user input
        $username = $this->security->xss_clean($this->input->post('username'));
        $password = $this->security->xss_clean($this->input->post('password'));
        // Prep the query
        $this->db->where('username', $username);
        $this->db->where('password', $password);
        // Run the query
        $query = $this->db->get('users');
        // Let's check if there are any results
        if($query->num_rows == 1)
        {
            // If there is a user, then create session data
            $row = $query->row();
            $data = array(
                    'userid' => $row->userid,
                    'fname' => $row->fname,
                    'lname' => $row->lname,
                    'username' => $row->username,
                    'validated' => true
                    );
            $this->session->set_userdata($data);
            return true;
        }
        // If the previous process did not validate
        // then return false.
        return false;
    }
}
?>

我可以确认进程函数正在加载,但是$results = $result = $this->users->validate(); 下面的任何代码都没有出现。模型也在加载,一旦我尝试调用函数,脚本就会自行杀死。

对不起,如果这个问题有点平淡无奇。

谢谢彼得

这一切都归结为我的代码。 模型类名必须等于模型文件的名称。

所以在这种情况下,我应该将我的文件命名为 login_model.php 然后必须调用类本身 Login_model (第一个字符必须是大写的,所有其他字符必须是小写的)。在控制器中调用模型时,它必须全部为小写,如下所示:

$this->load->model('login_model');

希望这对将来的任何人有所帮助,感谢所有人的努力和评论:)

你尝试将文件名大写?user_model.php User_model.php?