示例#1
0
 public function run()
 {
     $model = new Comments();
     if (!is_string($this->model)) {
         $model->post_id = $this->model->getPrimaryKey();
         $model->module = get_class($this->model);
         $order = '';
     } else {
         $model->post_id = 0;
         $model->module = $this->model;
         $order = 'DESC';
     }
     //  Получаем комментарии этого модуля и пост айди
     $models = Comments::getComments($model->module, $model->post_id, $order);
     //  Получаем кол-во страниц комментариев для редиректа
     $page = $models['pages']->totalCount / $models['pages']->pageSize + 1;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Url::remember(Url::current());
             Yii::$app->getSession()->setFlash('success', '<i class="fa fa-check fa-1x"></i> Good! ');
             if (!is_string($this->model)) {
                 return Yii::$app->getResponse()->redirect('/post/' . $this->model->slug . '/' . $model->post_id . '?page=' . round($page) . '#' . $model->id);
             } else {
                 return Yii::$app->getResponse()->refresh();
             }
         }
     }
     return $this->render('widgetComment', ['model' => $model, 'models' => $models['models'], 'pages' => $models['pages'], 'options' => $this->options]);
 }
示例#2
0
 /**
  * Creates a new Comments model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Comments();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }