Hello,
i'm writing my personal library for Users.
but i have a problem trying to query my db.
is wrong call db from Lib?
PHP Code:
Class User
{
public function __construct(){
}
public function userExists($id){
$query = $this->db->get_where('users', array('id' => $id));
$number = $query->num_rows();
if($number > 0)
return true;
else
return false;
}
}
obviously in my controller i loaded the lib with
PHP Code:
$this->load->library('user');
the error is
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: User::$db
Filename: libraries/User.php
Line Number: 28
Backtrace:
File: /web/htdocs/www.mysite.com/home/API/application/libraries/User.php
Line: 28
Function: _error_handler
File: /web/htdocs/www.mysite.com/home/API/application/controllers/User_authentication.php
Line: 29
Function: userExists
File: /web/htdocs/www.mysite.com/home/API/index.php
Line: 315
Function: require_once
Fatal error: Call to a member function get_where() on a non-object in /web/htdocs/www.mysite.com/home/API/application/libraries/User.php on line 28
A PHP Error was encountered
Severity: Error
Message: Call to a member function get_where() on a non-object
Filename: libraries/User.php
Line Number: 28
Backtrace:
is a good way?