Welcome Guest, Not a member yet? Register   Sign In
What does $this refer to in a Model?
#11

(This post was last modified: 01-30-2016, 05:30 AM by dangyuluo.)

(01-29-2016, 03:41 AM)Narf Wrote:
(01-29-2016, 03:06 AM)dangyuluo Wrote:
(01-29-2016, 02:06 AM)Narf Wrote: By actually reading my second sentence and those links? Smile

I'm not trying to offend you, but maybe you misunderstand my question.
I can surely use _get to get access to function and variable of CI_Controller. I have known that quite before.
But my question actually is, since I have experimented before, why can I use $this->cache->redis in a model, in which $this should refer to the Model Class, not the CI_Controller?

No offense taken, but you're contradicting yourself ...

If you knew how __get() works (that's two underscores, not one), then you wouldn't be asking this question. And if you don't understand it - you didn't really follow through that first link, which explains it:

Code:
$this->cache

Is interpreted by PHP (given the current state of your class) as:

Code:
[current class instance] -> [inaccessible or non-existent property]

And gets executed as:

Code:
[current class instance] -> __get([name of the inaccessible or non-existent property])

That's what __get() is made for, you don't use it as $this->__get($something) ... that'd be silly.


Ok guy, now I understand why you mentioned __get() function. Before that I thought it was only a function defined by Codeigniter. Thank you!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB