The example in this article describes how Yii generates views through small objects. Share it with everyone for your reference, the details are as follows:
We take manger as an example:
In the generated models file, find the corresponding table manger.php and then find attributeLabels. For example: 'name' => 'Name', here, change the following Name to the desired field. For example, my current user name is changed to 'name' => 'Username', here it is The widget is something to display.
Then model it in the controller
$manger = Manger::model();
Map this $manger to the view layer
$this->renderPartial('views',array('manger'=>$manger));
Use it in the view as follows:
//The above is to introduce the form
(This displayed user name)
input type=text case
(displayed input box)
//This actual input has type="text". If you want to display the password, use the following
input type=password case
Change textField to passwordField
select drop-down menu case
If you want a drop-down menu, you need to modify the information in the controller, how to modify it :
For example, my current type is
$type = Type::model(); $typeArr = $type->findAll(); foreach($typeArr as $k=>$v){ $t[$v['id']] = $v['name'];//组合数组 }
Then map $t to the view, use method:
checkbos situation (multiple selection)
$attr below and $t in the drop-down menu are The same amount needs to be obtained into an array in the controller layer first
radio situation, (single choice)
$attr situation is the same as above
(end form form)
I hope this article will help everyone use PHP based on the Yii framework Programming helps.
For more articles related to Yii’s method of generating views through small objects, please pay attention to the PHP Chinese website!