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

(01-29-2016, 11:32 AM)LeMec Wrote:
(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.

When my grand kids ask me: Grampa! What did you really accomplish in your life?

I will answer: Well I had a huge impact on the CodeIgniter community by making one of the most knowledgeable person on that site become a lot more patient  Tongue

LeMec, I don't understand why you would post such a thing. Here is Narf trying to help somebody, and you are like a heckler, a court jester, or maybe just a modern forum troll. The last thread I watched you basically hijack was all about your personal grudge against Narf and his lack of explaining things to your satisfaction. In the end, the OP was satisfied, and he/she seemed confused or amused about your rant than anything else. It's pretty rude to hijack threads, and I don't have any moderation powers here, but if I did I'd be scolding you right now.
Reply


Messages In This Thread
RE: What does $this refer to in a Model? - by skunkbad - 01-29-2016, 03:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB