PHP development framework YiiFramework tutorial (7) Use CHtml to create Form

Source: Internet
Author: User
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.

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.