Yii Tutorial
Yii Useful Resources
Selected Reading
- Gii – Generating Module
- Gii – Generating Controller
- Gii – Creating a Model
- Yii - Gii
- Yii - Localization
- Yii - Authorization
- Yii - Authentication
- Yii - Error Handling
- Yii - Logging
- Yii - Aliases
- Yii - Fragment Caching
- Yii - Caching
- Yii - Testing
- Yii - Fields
- Yii - RESTful APIs in Action
- Yii - RESTful APIs
- Yii - Theming
- Yii - Database Migration
- Yii - Active Record
- Yii - Query Builder
- Yii - Data Access Objects
- Yii - Database Access
- Yii - Dependency Injection
- Yii - Configurations
- Yii - Creating a Behavior
- Yii - Behaviors
- Yii - Creating Event
- Yii - Events
- Yii - GridView Widget
- Yii - ListView Widget
- Yii - Data Widgets
- Yii - Data Providers
- Yii - Properties
- Yii - Sorting
- Yii - Pagination
- Yii - Formatting
- Yii - Files Upload
- Yii - Using Cookies
- Yii - Cookies
- Yii - Using Flash Data
- Yii - Sessions
- Yii - AJAX Validation
- Yii - Ad Hoc Validation
- Yii - Validation
- Yii - HTML Forms
- Yii - Rules of URL
- Yii - URL Routing
- Yii - URL Formats
- Yii - Responses
- Yii - HTTP Requests
- Yii - Creating Extensions
- Yii - Extensions
- Yii - Asset Conversion
- Yii - Assets
- Yii - Layouts
- Yii - Views
- Yii - Modules
- Yii - Widgets
- Yii - Models
- Yii - Using Actions
- Yii - Using Controllers
- Yii - Controllers
- Yii - Entry Scripts
- Yii - Application Structure
- Yii - Create Page
- Yii - Installation
- Yii - Overview
- Yii - Home
Yii Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Yii - ListView Widget
Yii - ListView Widget
The ListView widget uses a data provider to display data. Each model is rendered using the specified view file.
Step 1 − Modify the actionDataWidget() method this way.
pubpc function actionDataWidget() { $dataProvider = new ActiveDataProvider([ query => MyUser::find(), pagination => [ pageSize => 20, ], ]); return $this->render( datawidget , [ dataProvider => $dataProvider ]); }
In the above code, we create a data provider and pass it to the datawidget view.
Step 2 − Modify the datawidget view file this way.
<?php use yiiwidgetsListView; echo ListView::widget([ dataProvider => $dataProvider, itemView => _user , ]); ?>
We render the ListView widget. Each model is rendered in the _user view.
Step 3 − Create a file called _user.php inside the views/site folder.
<?php use yiihelpersHtml; use yiihelpersHtmlPurifier; ?> <span class = "user"> <?= $model->id ?> <?= Html::encode($model->name) ?> <?= HtmlPurifier::process($model->email) ?> </span>
Step 4 − Type http://localhost:8080/index.php?r=site/data-widget in the address bar of the web browser, you will see the following.
![ListView Widget Example Output](/yii/images/pstview_widget_example_output.jpg)