/** * @inheritdoc */ public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($insert) { if (!$this->author_id) { $this->author_id = Yii::$app->user->id; } if (!$this->status_id) { $this->status_id = self::STATUS_ACTIVE; } } return true; } else { return false; } }
/** * @return \yii\db\ActiveQuery */ public function getComments() { return $this->hasMany(Comment::className(), ['model_class' => 'id']); }
/** * @inheritdoc */ public function scenarios() { $scenarios = parent::scenarios(); $scenarios['admin-update'] = ['status_id', 'content']; return $scenarios; }