CodeIgniter - 调用非对象上的成员函数select() [英] CodeIgniter - Call to a member function select() on a non-object

查看:300
本文介绍了CodeIgniter - 调用非对象上的成员函数select()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CodeIgniter的新手。这是我的代码:

I'm quite new to CodeIgniter. This is my code:

class User_model extends CI_Model {

    function validate_user() {

        $this->db->select('*');
        $this->db->from('user');
        $this->db->where('username', $this->input->post('username'));
        $this->db->where('password', md5($this->input->post('password')));
        $validate_user = $this->db->get();

        if($validate_user->num_rows == 1) {
            return TRUE;
        }
    }
}

错误在我的模型文件中:

I'm, receiving this error in my model file:

Call to a member function select() on a non-object

目前我使用的是CodeIgniter 2.1.0版。请帮助我!

Currently I'm using CodeIgniter version 2.1.0. Please help me!

推荐答案

我认为你必须加载数据库库。第一种方式是在应用程序中包含数据库/ config / autoload.php

I think that you have to load the "database" library. The first way is to include the "database" in your application/config/autoload.php

$autoload['libraries'] = array('database', 'session');

或在您的类构造函数中:

or in your class constructor:

class User_model extends CI_Model { 

     public function __construct() 
     {
           parent::__construct(); 
           $this->load->database();
     }
}



您可以在这里获得更多信息:http://ellislab.com/codeigniter/user_guide/database/connecting.html

这篇关于CodeIgniter - 调用非对象上的成员函数select()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆