public function create() { if (!Yii::$app->user->isGuest) { $this->created_by = Yii::$app->user->id; } if ($this->validate()) { return Yii::$app->db->transaction(function () { $comment = new Comment(); $comment->setAttributes($this->attributes, false); if (empty($this->parent_id)) { $comment->level = 0; } else { $comment->level = Comment::findOne(['id' => $this->parent_id])->level; $comment->level++; } $comment->status = 1; $comment->created_at = (new \DateTime())->format('Y-m-d H:i:s'); $comment->save(false); return true; }); } return false; }