CodeIgniter Forums
Problem using models with codeigniter 2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem using models with codeigniter 2 (/showthread.php?tid=52750)



Problem using models with codeigniter 2 - El Forum - 06-25-2012

[eluser]fatman[/eluser]
Hi,

I'm using the latest version and I'm trying to write a very simple model:

Code:
<?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 from the controller I call it by:

Code:
$this->model->test();

But when i'm calling the controller i get this:

Code:
<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 a member of the object, any clue why?



Problem using models with codeigniter 2 - El Forum - 06-25-2012

[eluser]Matalina[/eluser]
did you autoload the database?


Problem using models with codeigniter 2 - El Forum - 06-25-2012

[eluser]n0xie[/eluser]
Code:
order_by()



Problem using models with codeigniter 2 - El Forum - 06-25-2012

[eluser]fatman[/eluser]
You are both right, thanks.