public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => AccessControl::className(),
'only' => ['create', 'update', 'delete', 'view', 'index'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied by default
],
],
[
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['update_time'],
],
],
];
}
上面的代碼用於我的控制器行爲功能。在創建或更新時,'create_time'和'update_time'字段沒有按當前時間更新。這些字段的類型設置爲日期時間。請你需要你的幫助。TimestampBehavior在Yii2中不工作
編寫規則 – zelenin 2014-11-03 08:06:24