Codeigniter中的错误: - 调用未定义的方法CI_Loader :: select()

时间:2017-05-14 13:37:27

标签: php codeigniter

我创建了View,Controller Model并将数据库与codeigniter项目连接起来。 我已经使用数据库配置codeigniter。 但是,当我运行项目它给我错误如下: -

消息:调用未定义的方法CI_Loader :: select()

我的观点是: - 的login.php

<html>
    <head>
        <title>Login to Dhoami Enterprice</title>
        <script src="<?php echo base_url();?>/assets/js/jquery-3.2.1.js"></script>
        <script src="<?php echo base_url();?>/assets/js/sweetalert.min.js"></script>
        <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/assets/css/sweetalert.css">
    <head>
    <body>
        <form id="login_form" method="POST" >
            <input type="text" name="u_name" placeholder="Enter E-mail">
            <input type="text" name="u_pass" placeholder="Enter Password">
            <button type="submit" name="login_submit">Login</button>
        </form>
    </body>
    <script>
    /*  function login(){
            var form_data = $('#login_form').serialize();
alert(form_data);
        } */
    $('#login_form').submit(function(e){
        e.preventDefault(); 
        var form_data = $('#login_form').serialize();
        $.ajax({
            type:'POST',
            url:'<?php echo base_url();?>/login/login_ajax',
            data:form_data,
            success: function(){
            },
            error:function(xhr){
                swal("An error occured: " + xhr.status + " " + xhr.statusText);
            }
        });
    });
    </script>
</html>

Cotroller是: - 的login.php

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

class Login extends CI_Controller {

    public function __construct()
    {
        parent::__construct();          
        $this->load->model('Login_model');          
    }
    public function index()
    {
        $this->load->view('login');
    }
    public function login_ajax(){
        $user_email = $this->input->post('uname');
        $user_password = $this->input->post('upass');
        $user_password = hash('sha512', $user_password);
        $where = array('email'=>$user_email,'password'=>$user_password);
        $data['user_status'] = $this->Login_model->check_user($where);
        print_r($data['user_status']);
    }
}

ModelIs如下: - Login_model.php

<?php
class Login_model extends CI_Model {

    public function __construct() {
        parent::__construct();
        $this->db = $this->load->database('default');
    }
    public function check_user($where){
        $this->db->select('*');
        $this->db->from('user');
        $this->db->where($where);
        $query = $this->db->get();
        echo $this->db->last_query();
        //return $query->result_array();
    }
}
?>

1 个答案:

答案 0 :(得分:2)

根据CodeIgniter's source$this->load->database('default')调用将返回CI_Loader类的实例,除非您传递了第二个布尔值的poaremter。

所以,基本上,它应该是

$this->db = $this->load->database('default', true);

P.S。你真的不应该在任何项目中使用CodeIgniter。