Home > php教程 > PHP开发 > Yii method to generate views through small objects

Yii method to generate views through small objects

高洛峰
Release: 2016-12-20 16:21:22
Original
1334 people have browsed it

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();
Copy after login

Map this $manger to the view layer

$this->renderPartial('views',array('manger'=>$manger));
Copy after login

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'];//组合数组
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template