search
Homephp教程PHP开发Yii method to generate views through small objects

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools