Here is the corrected version:
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['create_time'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['create_time'],
],
],
];
}
Here is deeper explanation.
The main problem is you forgot to wrap behavior config into its own array, that's why the error is thrown. This config as all others is processed by Yii::createObject() method. So you need array containing at least class element. In case you want default config you can omit this for brevity with just specifying class name, for example:
public function behaviors()
{
return [
TimestampBehavior::className(),
],
];
}
Besides that, you also forgot to close square bracket after attribute.
And finally, you should not specify attributes like that. It was like that at initial stage of this behavior, then it was refactored. Now you only need to specify according attribute names, for example:
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at', // This is by default, you can omit that
'updatedAtAttribute' => 'updated_at', // This is by default, you can omit that
],
],
];
}
Also I don't think that having the same column for tracking create and update time is a good idea.
Additionally you can specify value used to update these columns:
use yii\db\Expression;
...
'value' => new Expression('NOW()'),
This will involve database to calculate time, if you want to do it on server side via PHP, you can do use closure for example like this:
'value' => function () {
return date('Y-m-d H:i:s');
}
And one more thing even if it's not directly related with this problem - you can set alias for every behavior by setting a key of configuration array. This is called named behavior:
public function behaviors()
{
return [
'timestamp' => [
...
],
],
];
}
This was mentioned by @GAMITG in his answer.