When you create the MVC view of a YII application, you can directly construct the page view directly using the HTML language, and Yii also provides several help (helper) classes to simplify the view writing. For example, to create a text entry field, we can call Chtml::textfield (), and to create a drop-down list, call CHtml::d ropdownlist (). Some of the view in the previous hangman example is using cHTML to create a view.
Info: You might want to know the benefits of using help classes if they require the same amount of code as the amount of code that writes pure HTML directly. The answer is that the help class can provide more functionality than the HTML code. For example, the following code will generate a text input field that can touch the publication submit action when the user modifies its value.
Chtml::textfield ($name, $value, Array (' Submit ' => '));
Otherwise you'll need to write a whole bunch of JavaScript.
Recall the definition of the Hangman page play:
<p>this is the game of hangman.
You are must guess a word, a letter in a time.
If you are too many mistakes, you lose the game!</p> <?php
echo chtml::beginform ();?>
<?php Echo Chtml::radiobuttonlist (' level ', null, $levels);?>
<br/>
<?php echo Chtml::submitbutton (' play! '); ?>
<?php if ($error):?>
<span style= "color:red" >you must-choose a difficulty level!</span >
<?php endif?>
<?php echo chtml::endform ();?>
The CHtml Construction page always ends with a chtml::beginform () beginning with Chtml::endform (). In fact, these two methods generate the start and end tags of the from tag.
For UI components supported by HTML forms, such as button, RadioButton, Checkbutton, and other UI components, the cHTML class provides a corresponding method, such as the RadioButtonList and Submitbutton above.
In addition to RadioButtonList, cHTML also provides a set of activexxx, such as activeradiobuttonlist, which need to be used in conjunction with Cformmodel, For examples like hangman, we don't use model in addition, so we don't use the Activeradiobuttonlist method, and we'll introduce the model in MVC later.
You can refer to the Yii class reference documentation for all UI components supported by CHtml: 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 simplify form creation. This small object provides seamless, consistent validation both on the client and on the server side. These are described in conjunction with the UI components supported by Yii.
See a full set of tutorials: http://www.bianceng.cn/webkf/PHP/201301/35265.htm