Hello. I have this overriding getter in Users.php model:
public function __get($name)
And this is the field getter for field ‘CP’
public function getCP()
//here need some code to alter the 'CP' field result
But I obtain follow error:
Undefined property: Users::$cp
00176: public function getCP()
00178: return $this->cp;
How can I get the ‘CP’ field value?
First off, you don’t have to override __get, CComponent already does what you are doing.
Secondly, your get method is getCP, so you need to reference it as:
$this->CP or $this->getCP()
Yes, you don’t have to override __get() method. You just must define “cp” in your class:
And a corresponding method to get it’s value:
public function getCp()
To get cp’s value inside a class you should write: $this->getCp(). Outside a class you can use $class->cp or $class->CP or $class->getCp() because function method_exists() is case-insensitive.
… and you don’t need a getter at all, if you don’t need to change the value of $this->cp before returning.
Yes, I need to change value before return. Because of that, I have this issue