• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB not loading in MY_Model 2.0


I'm moving some code into the 2.0 framework. I have a MY_Model class, which I have moved into application/core.

class MY_Model extends CI_Model {
function __construct() {

I have several classes which extend this Model, like this one:

class News extends MY_Model {
public function __construct($id=0) {

My problem is, whenever I load one of my models, like this:

$this->load->model('news', '', true);
$n = new news(4);

I cannot access the db property. Calls to $this->db->query give me the error:

Fatal error: Call to a member function query() on a non-object in C:\Apache\htdocs\nhl\application\models\news.php on line 18

I have no problem connecting to the db if I don't use MY_Model. Any ideas?


Hummm, maybe the CI Super Object!
private $CI;

public function __construct()

    $this->CI =& get_instance();

$query = $this->CI->db->method();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.