Understanding Virtual Attributes and get/set methods

Comparing #2 with #3

Revision #3 was created by Maurizio Domba Cerin Maurizio Domba Cerin on Mar 31, 2011, 7:15:15 AM.

spaces adjustment

Content

[...]
```php
class Comment extends CActiveRecord {
public $helperVariable;
public function rules() { ... }
...
}
 
```
and then use them in the obvious way:
[...]
lastname VARCHAR(32),
...
)
 
~~~
Yii's Active Record maps these easily into the `Person` model, which allows you to reference and assign `$model->firstname` and `$model->lastname` attributes anywhere in your code. ActiveRecord is one of the coolest feature of Yii.
[...]
}
...
}
 
```
With this getter function defined, `$model->fullname` automatically calls the function and returns the value as if it were a real attribute: this is a **virtual** attribute, and it's very powerful.
[...]
```php
$x = $model->fullname;
    $x = $model->getFullname(); // same thing     $model->active = 1;     $model->setActive(1); // same thing
```

Note that Yii uses get/set functions **very** heavily internally, so when reviewing the class referneces, any function beginning with "set" or "get" can generally be used as an attribute.>

Resolving Conflicts
[...]