Yii2 DateTime Behavior
Initiates database date columns as DateTime PHP classes., (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist davidhirtz/yii2-datetime-behavior "*"
or add, (*4)
"davidhirtz/yii2-datetime-behavior": "*"
to the require section of your composer.json
file., (*5)
Usage
Once the extension is installed, simply use it in your code by adding it to your ActiveRecord behavior. If you don't set the attributes all "date" and "datetime" columns will be automatically selected., (*6)
use davidhirtz\yii\datetime\DateTimeBehavior;
public function behaviors()
{
return [
[
'class'=>DateTimeBehavior::className(),
//'attributes'=>['custom_attribute', 'another_attribute'],
],
];
}