Models
In Yii1, base models and form models were two separated classes (CModel
and CFormModel
). In Yii2, these two classes have been consolidated into a single class, yii/base/Model
. This class is used throughout Yii2 for data representation and should be our go-to class when representing data we can't represent with yii/db/ActiveRecord
.
Tip
Since yii/db/ActiveRecord
extends yii/base/Model
, we're already familiar with the majority of methods and properties that yii/base/Model
offers, such as getAttributes()
, rules()
, attributeLabels()
, and getErrors()
. Refer to the Yii2 API documentation for a complete list of all the methods supported by yii/base/Model
at http://www.yiiframework.com/doc-2.0/yii-base-model.html.
Model attributes
In yii/db/ActiveRecord
, data attributes and attribute names are pulled directly from our database column names. In yii/base/Model
, data attributes and attribute names are defined as public properties within our model class. For instance, if we want to create...