Welcome Guest, Not a member yet? Register   Sign In
Accessing $this->db from within a model
#1

[eluser]Unknown[/eluser]
Hi everybody,

I am using CI 2.1.0 and autoload the database library. Inside a controller, var_dump($this->db) shows the database object. If I load a model inside the controller, var_dump($this->db) inside the model just outputs "bool(false)". However, getting a CI instance (inside the model) and referencing the db object via the CI object:

$this->CI =& get_instance();
var_dump($this->CI->db);

works too. Might I miss something? I expected $this->db to be directly accessible inside a model, like the documentation example shows:
http://ellislab.com/codeigniter/user-gui...odels.html

I was also trying to load the model this way inside the controller:
$this->load->model('User_model', 'user', true);

But with the same results. The DB connection itself works, I can execute queries, read their results and so on within my model, but by using $this->CI->db, not via $this->db.

Thanks in advance,
Alex.




Theme © iAndrew 2016 - Forum software by © MyBB