Skip to content

Instantly share code, notes, and snippets.

@thyseus
Created July 6, 2017 12:18
Show Gist options
  • Save thyseus/9a634096790c4d672a9fa6dd65779a18 to your computer and use it in GitHub Desktop.
Save thyseus/9a634096790c4d672a9fa6dd65779a18 to your computer and use it in GitHub Desktop.
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
// if you're using datetime instead of UNIX timestamp:
// 'value' => new Expression('NOW()'),
],
];
}
@thyseus
Copy link
Author

thyseus commented Jul 6, 2017

use yii\behaviors\BlameableBehavior;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;

public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'value' => new Expression('NOW()'),
            ],
            [
                'class' => BlameableBehavior::className(),
            ],
            [
                'class' => SluggableBehavior::className(),
                'attribute' => 'title',
            ],
        ];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment