Difference between #2 and #3 of
Understanding Virtual Attributes and get/set methods

Revision #3 has been created by Maurizio Domba Cerin on Mar 31, 2011, 7:15:15 AM with the memo:

spaces adjustment
« previous (#2) next (#4) »

Changes

Title unchanged

Understanding Virtual Attributes and get/set methods

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

Virtual Attributes; __get; __set

Content changed

[...]
```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
[...]
66 0
44 followers
Viewed: 202 618 times
Version: 1.1
Category: Tutorials
Written by: Steve Friedl
Last updated by: GOsha
Created on: Mar 31, 2011
Last updated: 12 years ago
Update Article

Revisions

View all history