Пример #1
0
 /**
  * Creates a new Comments model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $ajax = Yii::$app->request->post('ajax');
     $model = new Comments();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($ajax) {
             return json_encode($model->toArray());
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         if ($ajax) {
             return json_encode($model->getErrors());
         }
         return $this->render('create', ['model' => $model]);
     }
 }