Exemplo n.º 1
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 ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
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 ($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()]);
     }
 }
Exemplo n.º 3
0
 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()]);
     }
 }
Exemplo n.º 4
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 (isset($_POST['Post'])) {
         $model->attributes = $_POST['Post'];
         $model->setAttribute('id', $model->id);
         $model->setAttribute('nama', Yii::$app->user->identity->nama);
         $model->setAttribute('kategory_forum', Yii::$app->session['forum_id']);
         $model->setAttribute('judul', $model->judul);
         $model->setAttribute('isi_post', $model->isi_post);
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('success', 'Posting Anda telah ditambahkan');
             $this->redirect(['index']);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }