Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
9d961a30
Commit
9d961a30
authored
Dec 27, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ListView description to data widgets guide
parent
94596109
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
1 deletion
+55
-1
output-data-widgets.md
docs/guide/output-data-widgets.md
+55
-1
No files found.
docs/guide/output-data-widgets.md
View file @
9d961a30
...
...
@@ -6,6 +6,60 @@ Data widgets
ListView
--------
The ListView widget is used to display data from data provider. Each data model is rendered using the view specified.
Since it provides features such as pagination, sorting and filtering out of the box, it is handy both to display
information to end user and to create data managing UI.
A typical usage is as follows:
```
php
use
yii\widgets\ListView
;
use
yii\data\ActiveDataProvider
;
$dataProvider
=
new
ActiveDataProvider
([
'query'
=>
Post
::
find
(),
'pagination'
=>
[
'pageSize'
=>
20
,
],
]);
echo
ListView
::
widget
([
'dataProvider'
=>
$dataProvider
,
'itemView'
=>
'_post'
,
]);
```
The
`_post`
view could be the following:
```php
<?php
use yii\helpers\Html;
use yii\helpers\HtmlPurifier;
?>
<div class="post">
<h2><?= Html::encode($model->title) ?></h2>
<?= HtmlPurifier::process($model->text) ?>
</div>
```
In the view above current data model is available as
`$model`
. Additionally the following are available:
-
`$key`
: mixed, the key value associated with the data item.
-
`$index`
: integer, the zero-based index of the data item in the items array returned by data provider.
-
`$widget`
: ListView, this widget instance.
If you need to pass additional data to each view use
`$viewParams`
like the following:
```
php
echo
ListView
::
widget
([
'dataProvider'
=>
$dataProvider
,
'itemView'
=>
'_post'
,
'viewParams'
=>
[
'fullView'
=>
true
,
],
]);
```
DetailView
...
...
@@ -421,7 +475,7 @@ $query->andFilterWhere(['LIKE', 'author.name', $this->getAttribute('author.name'
> Info: For more information on `joinWith` and the queries performed in the background, check the
> [active record docs on joining with relations](db-active-record.md#joining-with-relations).
#### Using
sql
views for filtering, sorting and displaying data
#### Using
SQL
views for filtering, sorting and displaying data
There is also another approach that can be faster and more useful - sql views. For example, if we need to show the gridview
with users and their profiles, we can do so in this way:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment