/** * Creates a new Game model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $Game = new Game(); if ($Game->load(Yii::$app->request->post()) && $Game->save()) { return $this->redirect(['game/index']); } else { return $this->render('create', ['Game' => $Game]); } }
/** * Loads game from session. * @return Game * @throws InvalidValueException */ public static function fromSession() { $session = Yii::$app->session->get('game'); if ($session === false) { throw new InvalidValueException('Saved game ID not found!'); } $game = new Game(); $game->load($session); return $game; }
/** * Handle the event. * * @param \App\Models\Game $game * @param \App\WS\Connection $conn * @return void */ public function handle($game, $user, $conn) { $game->load('countUsers'); foreach ($conn->clients() as $client) { $this->send($client, 'game.update', $game); } foreach ($conn->gameClients($game) as $client) { $this->send($client, 'game.left', $user); } }
/** * Load * @param string $id */ public function actionLoad($id) { $game = new Game(); $game->load($id); return $this->redirect(['game/play']); }