コード例 #1
0
 public function generateComment()
 {
     $games = Game::find()->all();
     foreach ($games as $game) {
         $comment = new CommentForm();
         $comment->game_id = $game['id'];
         $comment->author_id = $this->user_id;
         $comment->title = $this->fake->text(32);
         $comment->content = $this->fake->realText(400);
         $comment->save();
     }
 }
コード例 #2
0
 public function actionView()
 {
     $id = Yii::$app->request->get('id');
     $game = Game::findOne($id);
     $comments = Comment::find()->orderBy('id DESC')->where(['game_id' => $id])->all();
     $commentForm = new CommentForm();
     $commentForm->game_id = $id;
     if (!Yii::$app->user->isGuest && $commentForm->load(Yii::$app->request->post()) && $commentForm->save()) {
         $this->refresh();
     }
     return $this->render('view', ['game' => $game, 'commentForm' => $commentForm, 'comments' => $comments]);
 }