简体   繁体   中英

Error in Codeigniter :- Call to undefined method CI_Loader::select()

I have Created View, Controller Model and connect the database with the codeigniter project. And i have already configures codeigniter with database. But when i run the project It Gives me the Error as follow:-

Message: Call to undefined method CI_Loader::select()

My View is:- 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 is:- 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 as Follow:- 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();
    }
}
?>

According to CodeIgniter's source , the $this->load->database('default') call will return an instance of CI_Loader class unless you pass a second boolean poaremter.

So, basically, it should be

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

PS you really should not use CodeIgniter in any new projects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM