O'Reilly logo

Yii Rapid Application Development Hotshot by James R. Hamilton III, Lauren J. O'Meara

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Developing the Controller – Creating the DB Entry

We will put code in the create action for the Hangman controller to do four basic things:

  1. Pick a title at random.
  2. Generate a token.
  3. On success, create the record, and redirect to play, passing the token as a parameter.
  4. On failure, display the error in the view.

Engage Thrusters

  1. Open protected/controllers/HangmanController.php and add the following function at the top of the HangmanController class:
      private function errorAndEnd($action, $error) {
        $this->render($action, array('error' => $error));
        Yii::app()->end();
      }

    When called, this will pass error to the view and cause the application to terminate.

  2. Then add code to actionCreate() so it looks like the following:
    public function actionCreate() { $error ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required