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
22376910
Commit
22376910
authored
Dec 28, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Guide to pagination
parent
6e83bf5e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
4 deletions
+43
-4
README.md
docs/guide/README.md
+1
-1
output-pagination.md
docs/guide/output-pagination.md
+42
-3
No files found.
docs/guide/README.md
View file @
22376910
...
@@ -97,7 +97,7 @@ Displaying Data
...
@@ -97,7 +97,7 @@ Displaying Data
---------------
---------------
*
[
Data Formatting
](
output-formatter.md
)
*
[
Data Formatting
](
output-formatter.md
)
*
**TBD**
[
Pagination
](
output-pagination.md
)
*
[
Pagination
](
output-pagination.md
)
*
**TBD**
[
Sorting
](
output-sorting.md
)
*
**TBD**
[
Sorting
](
output-sorting.md
)
*
[
Data Providers
](
output-data-providers.md
)
*
[
Data Providers
](
output-data-providers.md
)
*
[
Data Widgets
](
output-data-widgets.md
)
*
[
Data Widgets
](
output-data-widgets.md
)
...
...
docs/guide/output-pagination.md
View file @
22376910
Pagination
Pagination
==========
==========
> Note: This section is under development.
When there's too much data to be displayed on a single page at once it's often divided into
>
parts each containing some data items and displayed one part at a time. Such parts are called
> It has no content yet.
pages thus the name pagination.
If you're using
[
data provider
](
output-data-providers.md
)
with one of the
[
data widgets
](
output-data-widgets.md
)
pagination is already sorted out for you automatically. If not, you need to create
[
[\yii\data\Pagination
]
]
object, fill it with data such as
[
[\yii\data\Pagination::$totalCount|total item count
]
],
[
[\yii\data\Pagination::$pageSize|page size
]
] and
[
[\yii\data\Pagination::$page|current page
]
], apply
it to the query and then feed it to
[
[\yii\widgets\LinkPager|link pager
]
].
First of all in controller action we're creating pagination object and filling it with data:
```
php
function
actionIndex
()
{
$query
=
Article
::
find
()
->
where
([
'status'
=>
1
]);
$countQuery
=
clone
$query
;
$pages
=
new
Pagination
([
'totalCount'
=>
$countQuery
->
count
()]);
$models
=
$query
->
offset
(
$pages
->
offset
)
->
limit
(
$pages
->
limit
)
->
all
();
return
$this
->
render
(
'index'
,
[
'models'
=>
$models
,
'pages'
=>
$pages
,
]);
}
```
Then in a view we're outputting models for the current page and passing pagination object to the link pager:
```
php
foreach
(
$models
as
$model
)
{
// display $model here
}
// display pagination
echo
LinkPager
::
widget
([
'pagination'
=>
$pages
,
]);
```
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