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
f2a3dafb
Commit
f2a3dafb
authored
Feb 27, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added `Pagination::getLinks()`
parent
6659919a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Pagination.php
framework/data/Pagination.php
+30
-0
No files found.
framework/CHANGELOG.md
View file @
f2a3dafb
...
...
@@ -145,6 +145,7 @@ Yii Framework 2 Change Log
-
Enh: Added
`yii\web\Response::clearOutputBuffers()`
(qiangxue)
-
Enh: Improved
`QueryBuilder::buildLimit()`
to support big numbers (qiangxue)
-
Enh: Added support for building SQLs with sub-queries (qiangxue)
-
Enh: Added
`Pagination::getLinks()`
(qiangxue)
-
Chg #1186: Changed
`Sort`
to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue)
-
Chg #1519:
`yii\web\User::loginRequired()`
now returns the
`Response`
object instead of exiting the application (qiangxue)
-
Chg #1586:
`QueryBuilder::buildLikeCondition()`
will now escape special characters and use percentage characters by default (qiangxue)
...
...
framework/data/Pagination.php
View file @
f2a3dafb
...
...
@@ -67,6 +67,12 @@ use yii\web\Request;
*/
class
Pagination
extends
Object
{
const
LINK_SELF
=
'self'
;
const
LINK_NEXT
=
'next'
;
const
LINK_PREV
=
'prev'
;
const
LINK_FIRST
=
'first'
;
const
LINK_LAST
=
'last'
;
/**
* @var string name of the parameter storing the current page index. Defaults to 'page'.
* @see params
...
...
@@ -217,4 +223,28 @@ class Pagination extends Object
{
return
$this
->
pageSize
<
1
?
-
1
:
$this
->
pageSize
;
}
/**
* Returns a whole set of links for navigating to the first, last, next and previous pages.
* @param boolean $absolute whether the generated URLs should be absolute.
* @return array the links for navigational purpose. The array keys specify the purpose of the links (e.g. [[LINK_FIRST]]),
* and the array values are the corresponding URLs.
*/
public
function
getLinks
(
$absolute
=
false
)
{
$currentPage
=
$this
->
getPage
();
$pageCount
=
$this
->
getPageCount
();
$links
=
[
self
::
LINK_SELF
=>
$this
->
createUrl
(
$currentPage
,
$absolute
),
];
if
(
$currentPage
>
0
)
{
$links
[
self
::
LINK_FIRST
]
=
$this
->
createUrl
(
0
,
$absolute
);
$links
[
self
::
LINK_PREV
]
=
$this
->
createUrl
(
$currentPage
-
1
,
$absolute
);
}
if
(
$currentPage
<
$pageCount
-
1
)
{
$links
[
self
::
LINK_NEXT
]
=
$this
->
createUrl
(
$currentPage
+
1
,
$absolute
);
$links
[
self
::
LINK_LAST
]
=
$this
->
createUrl
(
$pageCount
-
1
,
$absolute
);
}
return
$links
;
}
}
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