/**
  * 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]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ForumPost::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'score' => $this->score, 'id_user' => $this->id_user, 'id_topic' => $this->id_topic, 'createdAt' => $this->createdAt, 'updatedAt' => $this->updatedAt]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'meta_title', $this->meta_title])->andFilterWhere(['like', 'meta_description', $this->meta_description])->andFilterWhere(['like', 'meta_keyword', $this->meta_keyword]);
     return $dataProvider;
 }
 /**
  * Finds the ForumPost model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ForumPost the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ForumPost::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getForumPosts()
 {
     return $this->hasMany(ForumPost::className(), ['id_topic' => 'id']);
 }