use yii\behaviors\TimestampBehavior; public function behaviors() { return [ TimestampBehavior::className(), ]; }
use yii2tech\ar\softdelete\SoftDeleteBehavior; public function behaviors() { return [ 'softDelete' => [ 'class' => SoftDeleteBehavior::className(), 'softDeleteAttributeValues' => [ 'deleted_at' => time(), ], 'restoreAttributeValues' => [ 'deleted_at' => null, ], 'timestampExpression' => function ($model) { return new \yii\db\Expression('NOW()'); } ], ]; }In conclusion, the Yii2 ActiveRecord package library provides many useful behaviors that can be used to enhance the functionality of our database models. We can use the behaviors to add extra functionality to our models without having to write lots of custom code.