Welcome Guest, Not a member yet? Register   Sign In
DB not loading in MY_Model 2.0
#1

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

[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




Theme © iAndrew 2016 - Forum software by © MyBB