/**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     if ($model->load(Yii::$app->request->post())) {
         if (isset($model->create_day)) {
             $model->create_day = date("Y-m-d H:i:s");
         }
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id_post]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 3
0
 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     if (Yii::$app->request->isAjax) {
         $model->attributes = $_POST['Post'];
         if ($model->save()) {
             $response['files'] = ['ok'];
             $response['result'] = 'success';
             $response['post_list'] = $this->renderAjax('list_of_post', ['page_id' => $model->page_id]);
             return json_encode($response);
         } else {
             $response['result'] = 'error';
             $response['files'] = Html::errorSummary($model);
             return json_encode($response);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }