PHP development framework YiiFramework tutorial (7) Use CHtml to create Form
When creating the View of the Yii application MVC, you can directly construct the page View using the HTML language. Yii also provides several help (helper) classes to simplify View writing. For example, to create a text input field, call CHtml: textField (); to create a drop-down list, call CHtml: dropDownList (). Several views in the preceding Hangman example use CHtml to create a View.
Information: you may want to know the benefits of using the Help class, if the amount of code they need is equivalent to the amount of code that directly writes pure HTML. The answer is that the help class provides more functions than HTML code. For example, the following code generates a text input field, which can trigger the form submission action when the user modifies its value.
CHtml: textField ($ name, $ value, array ('submit '=> ''));
Otherwise, you need to write a lot of JavaScript.
Recall the definition of play on the page in Hangman:
This is the game of Hangman.
You must guess a word, a letter at a time.
If you make too then mistakes, you lose the game!
You must choose a difficulty level!
Using CHtml to construct a page always ends with CHtml: beginForm () and CHtml: endForm. In fact, two methods generate the start and end tags of the From tag.
For UI components supported by HTML forms, such as buttons, radioButton, and checkbutton, the CHtml class provides corresponding methods, such as the preceding radioButtonList and submitButton.
In addition to radioButtonList, CHtml also provides a set of activeXXX methods, such as activeRadioButtonList. these methods need to be used with CFormModel. for examples like Hangman, we do not use another Model, therefore, the activeRadioButtonList method is not used. we will introduce the Model in MVC later.
For all the UI components supported by CHtml, refer to the Yii Reference Document: http://www.yiiframework.com/doc/api/1.1/CHtml
Starting with version 1.1.1, a new small object CActiveForm (http://www.yiiframework.com/doc/api/1.1/CActiveForm) is provided to create a simplified form. This small object provides seamless and consistent verification between the client and the server. These are described in the UI components supported by Yii.