dev-master
9999999-devYii behavior for model attribute aliasing and format conversion using PHP MDH
BSD-3-Clause
The Requires
by Rangel Reale
yii2 model behavior format
Yii behavior for model attribute aliasing and format conversion using PHP MDH
The preferred way to install this extension is through composer., (*1)
Either run, (*2)
php composer.phar require --prefer-dist RangelReale/yii2-mdhaliasbehavior "*"
or add, (*3)
"RangelReale/yii2-mdhaliasbehavior": "*"
to the require
section of your composer.json., (*4)
This behavior adds an attribute alias that can perform format conversion between 2 data formats., (*5)
The aliased field by default is named
In your model:, (*7)
/** * @property string posted_at This is your property that you have in the database table, it has DATETIME format */ class Post extends ActiveRecord { // ... Some code here public function behaviors() { return [ 'alias' => [ 'class' => AliasBehavior::className(), // Our behavior 'attributes' => [ 'start_date' => [ 'dataType' => 'datetime', ], ], ] ]; } }
Behavior creates "virtual" attribute named attribute_name_alias for each attribute you define in the 'attributes' section.
When you read $yourModel->attribute_name_alias
behavior will return object with the type AliasAttribute. If
this object will be used in the string context, it will be converted to string with the magical __toString method.
And during this original value of attribute_name
will be converted into the local representation., (*8)
When you assign value to the $yourModel->attribute_name_alias
internally it will be assigned to value
property
of the AliasAttribute class and converted to the your database-stored property., (*9)
You can also define individual configuration for each attribute and define it's local name, format and so on., (*10)
Based on omnilight/yii2-datetime., (*11)
Yii behavior for model attribute aliasing and format conversion using PHP MDH
BSD-3-Clause
yii2 model behavior format