public function actionCreate() { $root = Comments::findOne(['depth' => 0]); if ($root === NULL) { $root = new Comments(['name' => 'root', 'note' => 'High level root']); $root->makeRoot(); } $id = Yii::$app->request->post('id', 1); $data = Yii::$app->request->post(); $parentComment = Comments::findOne(['id' => $id]); $childComment = new Comments(['name' => $data['name'], 'note' => $data['note']]); $childComment->appendTo($parentComment); \Yii::$app->response->format = 'json'; return Comments::serializeOne($childComment); }