Commit 01e892e9f0f53763369598e31d2908e40127447d
1 parent
a63984dc
подкорректировал логику добавления комментария
Showing
1 changed file
with
17 additions
and
4 deletions
Show diff stats
frontend/controllers/SiteController.php
| ... | ... | @@ -80,6 +80,7 @@ |
| 80 | 80 | )->orderBy([ new Expression('sort ASC NULLS LAST') ]) |
| 81 | 81 | ->all(); |
| 82 | 82 | $comments = Comment::find()->where(['status' => true, 'on_main' => true])->limit(6)->all(); |
| 83 | + | |
| 83 | 84 | $package = Package::find()->with(['language.alias'])->where(['status' => true])->orderBy('sort')->limit(3)->all(); |
| 84 | 85 | $settings = Settings::getInstance(); |
| 85 | 86 | return $this->render('index', [ |
| ... | ... | @@ -272,11 +273,15 @@ |
| 272 | 273 | } |
| 273 | 274 | |
| 274 | 275 | public function actionComments($service_id = null){ |
| 275 | - | |
| 276 | + | |
| 276 | 277 | if (\Yii::$app->request->isAjax){ |
| 277 | 278 | Yii::$app->response->format = Response::FORMAT_JSON; |
| 278 | 279 | $model = new Comment(); |
| 279 | - if ($model->load(\Yii::$app->request->post()) and $model->save()){ | |
| 280 | + #if ($model->load(\Yii::$app->request->post()) and $model->save()){ | |
| 281 | + if ($model->load(\Yii::$app->request->post())){ | |
| 282 | + if(!$model->entity_id)$model->entity_id=0; | |
| 283 | + $model->entity=Service::className(); | |
| 284 | + $model->save(); | |
| 280 | 285 | return [ |
| 281 | 286 | 'status' => true, |
| 282 | 287 | 'message' => 'Спасибо за Ваш отзыв. После проверки модератором он появиться на сайте' |
| ... | ... | @@ -288,14 +293,22 @@ |
| 288 | 293 | ]; |
| 289 | 294 | } |
| 290 | 295 | } |
| 296 | + | |
| 297 | + | |
| 298 | + # подкоректировал логику для сохранрения в БД/выдачи вопросов с категории "Общие вопросы" | |
| 299 | + # закрепил за ними entity_id=0 | |
| 300 | + if($service_id==null)$service_id=0; | |
| 291 | 301 | $dataProvider = new ActiveDataProvider([ |
| 292 | - 'query' => Comment::find()->where(['status' => true])->andWhere(['entity' => Service::className()])->andFilterWhere(['entity_id' => $service_id]), | |
| 302 | + 'query' => Comment::find() | |
| 303 | + ->where(['status' => true]) | |
| 304 | + ->andWhere(['entity' => Service::className()]) | |
| 305 | + ->andFilterWhere(['entity_id' => $service_id]),//'SELECT * FROM \"comment\" WHERE (\"status\"=TRUE) AND (\"entity\"=\'common\\models\\Service\')' | |
| 293 | 306 | 'pagination' => [ |
| 294 | 307 | 'pageSize' => 10, |
| 295 | 308 | ], |
| 296 | 309 | ]); |
| 297 | 310 | $services = Service::find()->where(['status' => true])->andWhere(['parent_id' => null])->all(); |
| 298 | - | |
| 311 | + | |
| 299 | 312 | return $this->render('comments', [ |
| 300 | 313 | 'dataProvider' => $dataProvider, |
| 301 | 314 | 'services' => $services, | ... | ... |