/** * @return string */ public function actionCreate() { if (Yii::$app->getRequest()->getIsAjax()) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $model = new CreateForm(); if ($model->load(Yii::$app->getRequest()->post(), '')) { if ($model->validate()) { $id = Yii::$app->getRequest()->post('topic_id'); if ($model->create($id)) { $count = Post::find()->where(['topic_id' => $model->getTopic()->id])->count(); $data['post'] = \post\widgets\Post::widget(['post' => $model->getPost(), 'count' => $count]); $data['post_id'] = $model->getPost()->getPrimaryKey(); $data['page'] = $this->getPageByPost($model->getPost()); return $data; } } else { return ['errors' => $model->getFirstErrors()]; } } } throw new NotFoundHttpException(); }