I’ve used Codeigniter 1.7 before and now I’ve upgraded to Codeigniter 2. I’m trying to write a very simple model:
<?php
class Test extends CI_Model{
function __construct(){
parent::__construct();
}
function test(){
$this->db->orderby ( 'updateDate', 'desc' );
$this->db->where ( 'logicalDelete', 0 );
$rs = $this->db->get ( 'act_activity_vw' );
if (! $rs) {
throw new DatabaseException ();
}
return $rs->result ();
}
}
And i have a simple controller that calls it. but when i try to run it i get the following error:
<b>Fatal error</b>: Call to a member function orderby() on a non-object in <b>C:\xampp\htdocs\API\application\models\test.php</b> on line <b>9</b><br />
It seems like it does not recognize ‘db’ as an object member.
Am i doing something wrong?
You need to load the database in your CodeIgniter system. You can do that with autoload or load it in the constructor of the class.
http://codeigniter.com/user_guide/database/connecting.html
I think that has everything you need.