/** * Creates a new Topic with a first Post * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionNew($id_category) { //Cr�ation du Topic $topic = new ForumTopic(); $topic->createdAt = date("Y-m-d H:i:s", time()); $topic->updatedAt = date("Y-m-d H:i:s", time()); $topic->id_category = $id_category; $topic->id_user = Yii::$app->user->id; $topic->status = 0; $post = new ForumPost(); //Test remplissage du formulaire if ($topic->load(Yii::$app->request->post()) && $post->load(Yii::$app->request->post())) { //Cr�ation du premier Post du topic $post->title = $topic->title; $post->score = 0; $post->createdAt = date("Y-m-d H:i:s", time()); $post->updatedAt = date("Y-m-d H:i:s", time()); $post->id_user = Yii::$app->user->id; if ($topic->save()) { $post->id_topic = $topic->id; if ($post->save()) { return $this->redirect(['/forum/default/posts', 'id_topic' => $topic->id]); } } } //Si formulaire mal rempli OU echec sauvegarde, renvoie le formulaire return $this->render('new', ['model' => $topic, 'post' => $post]); }