CodeIgniter Forums
DB not loading in MY_Model 2.0 - 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: DB not loading in MY_Model 2.0 (/showthread.php?tid=40571)



DB not loading in MY_Model 2.0 - El Forum - 04-12-2011

[eluser]Unknown[/eluser]
Hello,

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() {
parent::__construct();
...

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

class News extends MY_Model {
public function __construct($id=0) {
parent::__construct();
...

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?

Thanks!


DB not loading in MY_Model 2.0 - El Forum - 04-13-2011

[eluser]InsiteFX[/eluser]
Hummm, maybe the CI Super Object!
Code:
private $CI;

public function __construct()
{
    parent::__construct();

    $this->CI =& get_instance();
}

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

InsiteFX