PHP development framework YiiFramework tutorial (4) Hangman word game instance

Source: Internet
Author: User
With the previous "Hello, World" example and introduction to the basic YiiFrameworkWeb application, you can start to introduce a simple and complete Web application-Hangman (guessing word game ), this example is released with the Yii development kit. This example shows the basic steps for Yii application development. with the previous "Hello, World" example and introduction to the Yii Framework Web application, you can start to introduce a simple and relatively complete Web application-Hangman (guessing word game). This example was released with the Yii development kit. This example shows the basic steps for Yii application development.

Speaking of "Hangman" reminds me of the "word guessing game"-Hangman, which was completed on the CPC464 computer in the late 1980s s, let's move a villain away from the tornado. At that time, DOS just came out :-).

To develop a Web application, we first need to analyze the requirements. this is not part of this tutorial. but for the sake of completeness, we still need to list the rules for "guessing word games" below:

Word Game (Hangman, "Hanging Man") is a two-person game. One player wants one word, and the other tries to guess every letter in the player's words.

The word to be guessed is displayed in a horizontal line, allowing the player to know how many letters the word has. If a player guesses one of the letters, the other must write the letter at all positions where the letter appears. If the guess letter does not appear in the word, the other player will draw one of the hanging-neck dolls. The game will end in the following circumstances:

return array('name'=>'Hangman Game','defaultController'=>'game','components'=>array('urlManager'=>array('urlFormat'=>'path','rules'=>array('game/guess/'=>'game/guess',),),),);

All writable properties of the CWebApplication can be defined in the configuration file. we can see that the configuration file defines the application name as "Hangman Game ", then modify the default Controller name of the Web application to correspond to the GameController. if the defaultController is not redefined, the default Controller name is SiteController, in this way, the View will be stored in the protected/views/site Directory. In addition, the urlManager component is enabled for this Yii application. the functions of this component are described later. it is mainly used to define the URL format (routing format) that users can access ).

2. with this configuration file, you can use it in the entry script. the entry script index. php of each Yii application is similar, and most of the cases are Copy & Paste.

Now the Hangman game is complete. Although the game is simple, it illustrates the basic process of using Yii to develop applications. The following describes the development process provided by the Yii development documentation. Hangman is relatively simple and does not use databases or internationalization.

The development process here assumes that we have completed the analysis of application requirements and necessary design analysis.

Create a directory structure skeleton. The yiic tool described in the first Web application can be created to quickly implement this step.

Configure this application. This is achieved by modifying the application configuration file. You may also need to write some application components (such as user components) in this step ).

Creates a model class for each managed data type. The Gii tool described in Creating First Yii Application and Automatic Code Generation can be used to quickly create an active record class for each data table. 4. create a controller class for each type of user request. How to classify user requests depends on actual needs. In general, if a model class needs to be accessed by the user, it should have a corresponding controller class. The Gii tool can also automatically perform this step.

Implement actions and their corresponding views. This is what you really need to do.

Configure necessary action filters in the controller class.

Create a topic if you need the topic function.

If you want to internationalize (I18N), create translation information.

Apply appropriate caching technologies to cache data points and view points.

Final adjustment and deployment.

The above is the PHP development Framework Yii Framework tutorial (4) content of the Hangman word game instance. For more information, please follow the PHP Chinese network (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.