Home Backend Development PHP Tutorial Yii Framework Development Tutorial Zii Component-GridView Example_PHP Tutorial

Yii Framework Development Tutorial Zii Component-GridView Example_PHP Tutorial

Jul 14, 2016 am 10:07 AM
framework yii by develop Tutorial of Example components sheet

CGridView displays data in the form of tables. CGridView also supports paging and sorting. The most basic usage of CGridView and ListView type is also by setting the data provider, usually CActiveDataProvider.

Modify the previous example Yii Framework Development Tutorial (31) Zii Component-DetailView example and change the ListView to GridView:
[php]
widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'ajaxUpdate'=>false,
'template'=>'{pager}{summary}{items}{pager}',
)); ?>
widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'ajaxUpdate'=>false,
'template'=>'{pager}{summary}{items}{pager}',
)); ?>
The results are displayed as follows:
Yii Framework Development Tutorial Zii Component-GridView Example_PHP Tutorial
You can see that GridView displays all fields by default and uses the default format to display fields. If you need to control field display and format, you can configure the CGridView::columns property. Each column of GridView is a CGridColumn object:
Yii Framework Development Tutorial Zii Component-GridView Example_PHP Tutorial
CGridColumn is the base class of all Grid list items. Each table instance can have a header, multiple data cells, and an optional footer cell.
CButtonColumn indicates that the cell is one or more buttons. By default, three buttons are displayed, "view", "update" and "delete", which can be changed by setting buttons and template.
CCcheckBoxColumn indicates that the cell is a Checkbox, supports read-only, single-select or multi-select, and can be modified by configuring selectableRows
CDataColumn indicates that the unit is data or expression. By configuring name or value, the former represents the attribute name of the data model, and the latter codes a PHP expression.
CLinkColumn represents a hyperlink, and the link is set by configuring label, url or imageUrl.
Redefine the columns attribute of GridView as follows:
[php]
widget('zii.widgets.grid.CGridView', array(
'id'=>'person-grid',
'dataProvider'=>$dataProvider,
'htmlOptions'=>array('style'=>'width:740px'),
'pager'=>array(
                                                                                                                                                                                     
        ),  
'columns'=>array(
array(
                  'header'=>'Name',  
                'type'=>'raw',  
                                                                                                                                                                                                                                                              having
                                                                             
$this->grid->controller->createUrl
                ("view",array("CustomerId"=>$data->CustomerId)))',
  
                    ),  
  
                'Company',  
  
                array(  
                    'class'=>'CLinkColumn',  
                    'header'=>'Email',  
                    'imageUrl'=>'images/email.png',  
                    'labelExpression'=>'$data->Email',  
                    'urlExpression'=>'"mailto://".$data->Email',  
                    'htmlOptions'=>array('style'=>'text-align:center'),  
                    ),  
                array(  
                    'class'=>'CButtonColumn',  
                    'deleteConfirmation'=>'Are you sure to delete this item?',  
                    ),  
                ),  
  
));  
?>  
 
widget('zii.widgets.grid.CGridView', array(
'id'=>'person-grid',
'dataProvider'=>$dataProvider,
'htmlOptions'=>array('style'=>'width:740px'),
'pager'=>array(
'maxButtonCount'=>'7',
),
'columns'=>array(
 
array(
'header'=>'Name',
'type'=>'raw',
'value'=>'CHtml::link($data->FirstName .
" " . $data->LastName,
$this->grid->controller->createUrl
("view",array("CustomerId"=>$data->CustomerId)))',
 
),
 
'Company',
 
array(
'class'=>'CLinkColumn',
'header'=>'Email',
'imageUrl'=>'images/email.png',
'labelExpression'=>'$data->Email',
'urlExpression'=>'"mailto://".$data->Email',
'htmlOptions'=>array('style'=>'text-align:center'),
),
array(
'class'=>'CButtonColumn',
'deleteConfirmation'=>'Are you sure to delete this item?',
),
),
 
));
?>
 
显示如下:
Yii Framework Development Tutorial Zii Component-GridView Example_PHP Tutorial
点击姓名可以显示DetailView。 ButtonColumn 的update,search,delete没有添加对应的view ,就留给你自己加上了。
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477835.htmlTechArticleCGridView 以表格的形式显示数据,CGridView 也支持分页和排序,CGridView最基本的用法和ListView类型,也是通过设置 data provider,通常是CActiveDat...
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Steps to adjust the format of pictures inserted in PPT tables Steps to adjust the format of pictures inserted in PPT tables Mar 26, 2024 pm 04:16 PM

1. Create a new PPT file and name it [PPT Tips] as an example. 2. Double-click [PPT Tips] to open the PPT file. 3. Insert a table with two rows and two columns as an example. 4. Double-click on the border of the table, and the [Design] option will appear on the upper toolbar. 5. Click the [Shading] option and click [Picture]. 6. Click [Picture] to pop up the fill options dialog box with the picture as the background. 7. Find the tray you want to insert in the directory and click OK to insert the picture. 8. Right-click on the table box to bring up the settings dialog box. 9. Click [Format Cells] and check [Tile images as shading]. 10. Set [Center], [Mirror] and other functions you need, and click OK. Note: The default is for pictures to be filled in the table

Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

How to set WPS value to automatically change color according to conditions_Steps to set WPS table value to automatically change color according to condition How to set WPS value to automatically change color according to conditions_Steps to set WPS table value to automatically change color according to condition Mar 27, 2024 pm 07:30 PM

1. Open the worksheet and find the [Start]-[Conditional Formatting] button. 2. Click Column Selection and select the column to which conditional formatting will be added. 3. Click the [Conditional Formatting] button to bring up the option menu. 4. Select [Highlight conditional rules]-[Between]. 5. Fill in the rules: 20, 24, dark green text with dark fill color. 6. After confirmation, the data in the selected column will be colored with corresponding numbers, text, and cell boxes according to the settings. 7. Conditional rules without conflicts can be added repeatedly, but for conflicting rules WPS will replace the previously established conditional rules with the last added rule. 8. Repeatedly add the cell columns after [Between] rules 20-24 and [Less than] 20. 9. If you need to change the rules, you can just clear the rules and then reset the rules.

Tutorial on how to turn off the payment sound on WeChat Tutorial on how to turn off the payment sound on WeChat Mar 26, 2024 am 08:30 AM

1. First open WeChat. 2. Click [+] in the upper right corner. 3. Click the QR code to collect payment. 4. Click the three small dots in the upper right corner. 5. Click to close the voice reminder for payment arrival.

Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Apr 07, 2024 am 09:10 AM

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Learn how to develop mobile applications using Go language Learn how to develop mobile applications using Go language Mar 28, 2024 pm 10:00 PM

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

PHP Tutorial: How to convert int type to string PHP Tutorial: How to convert int type to string Mar 27, 2024 pm 06:03 PM

PHP Tutorial: How to Convert Int Type to String In PHP, converting integer data to string is a common operation. This tutorial will introduce how to use PHP's built-in functions to convert the int type to a string, while providing specific code examples. Use cast: In PHP, you can use cast to convert integer data into a string. This method is very simple. You only need to add (string) before the integer data to convert it into a string. Below is a simple sample code

See all articles