public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => 'created_at',
ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at',
],
],
];
}
public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => 'created_at',
ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
],
'value' => new Expression('NOW()')
],
];
?>
public function behaviors()
{
return [
[
'class' => CorrectDateBehavior::class,
'format' => 'datetime',
'attributes' => [
'dateFrom' => 'date_from',
'dateTo' => 'date_to',
]
]
];
}
$model = new Post();
$model->date_from = 1524775512;
echo $model->dateFrom; // 26.4.2018 20:45:12
$model->dateFrom = '01.05.2018';
echo $model->date_from; // 1515110400