Dear Friend
I am not able to see the exact problem you are facing.
I perceive that getter function is not functioning in Models.
If a model directly derived from a CComponent, then there is not much problem.
The only thing we have to ensure that property has lesser degree of access than the getter and setter function.
class MyModel extends CComponent
{
protected $name="seeni"; //protected or private
public function getName()
{
return strrev($this->name);
}
public function setName($name)
{
$this->name=$name;
}
}
Now
$seeni=new MyModel;
echo $seeni->name;//returns inees;
$seeni->name="vasan";
echo $seeni->name;//returns nasav
The situation is not straight forward in CActiveRecord.
Here we have to override the __get and __set methods.
class User extends CActiveRecord
{
protected $native="India";
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'user';
}
public function __get($name)
{
$getter='get'.$name;
if(method_exists($this,$getter))
return $this->$getter();
else return parent::__get($name);
}
public function __set($name,$value)
{
$setter='set'.$name;
if(method_exists($this,$setter))
return $this->$setter($value);
else parent::__set($name,$value);
}
public function getNative()
{
return strrev($this->native);
}
public function setNative($native)
{
$this->native=$native;
}
...............................................
...............................................
Now
$user=new User;
echo $user->native;// returns aidnI
$user->native="USA";
echo $user->native;//returns ASU
Regards.