Welcome Guest, Not a member yet? Register   Sign In
Problem using models with codeigniter 2
#1

[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?
#2

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB