/** * 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()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'category' => Category::find()->all(), 'authors' => User::find()->all()]); } }
public function actionCreatepost() { if (\Yii::$app->user->isGuest) { return $this->run('site/login'); } $post = new Post(); $data = \Yii::$app->request->post("Post"); if (!empty($data)) { $post->load(\Yii::$app->request->post()); } if (!empty($data) && $post->validate() && $post->save()) { return $this->render('create_post_success', ['post' => $post]); } else { return $this->render('create_post', ['post' => $post, 'categoryList' => Category::getList()]); } }