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
8e8bbf4e
Commit
8e8bbf4e
authored
Feb 27, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved page size and page number validation.
parent
3653db4d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
+12
-7
Pagination.php
framework/data/Pagination.php
+12
-7
No files found.
framework/data/Pagination.php
View file @
8e8bbf4e
...
...
@@ -161,7 +161,8 @@ class Pagination extends Object
public
function
getPage
(
$recalculate
=
false
)
{
if
(
$this
->
_page
===
null
||
$recalculate
)
{
$this
->
setPage
((
int
)
$this
->
getQueryParam
(
$this
->
pageParam
,
1
)
-
1
);
$page
=
(
int
)
$this
->
getQueryParam
(
$this
->
pageParam
,
1
)
-
1
;
$this
->
setPage
(
$page
,
true
);
}
return
$this
->
_page
;
}
...
...
@@ -169,22 +170,24 @@ class Pagination extends Object
/**
* Sets the current page number.
* @param integer $value the zero-based index of the current page.
* @param boolean $validatePage whether to validate the page number. Note that in order
* to validate the page number, both [[validatePage]] and this parameter must be true.
*/
public
function
setPage
(
$value
)
public
function
setPage
(
$value
,
$validatePage
=
false
)
{
if
(
$value
===
null
)
{
$this
->
_page
=
null
;
}
else
{
$value
=
(
int
)
$value
;
if
(
$this
->
validatePage
)
{
if
(
$
validatePage
&&
$
this
->
validatePage
)
{
$pageCount
=
$this
->
getPageCount
();
if
(
$value
>=
$pageCount
)
{
$value
=
$pageCount
-
1
;
}
}
if
(
$value
<
0
)
{
$value
=
0
;
}
}
$this
->
_page
=
$value
;
}
}
...
...
@@ -201,24 +204,26 @@ class Pagination extends Object
if
(
$this
->
_pageSize
===
null
)
{
if
(
empty
(
$this
->
pageSizeLimit
))
{
$pageSize
=
$this
->
defaultPageSize
;
$this
->
setPageSize
(
$pageSize
);
}
else
{
$pageSize
=
(
int
)
$this
->
getQueryParam
(
$this
->
pageSizeParam
,
$this
->
defaultPageSize
);
$this
->
setPageSize
(
$pageSize
,
true
);
}
$this
->
setPageSize
(
$pageSize
);
}
return
$this
->
_pageSize
;
}
/**
* @param integer $value the number of items per page.
* @param boolean $validatePageSize whether to validate page size.
*/
public
function
setPageSize
(
$value
)
public
function
setPageSize
(
$value
,
$validatePageSize
=
false
)
{
if
(
$value
===
null
)
{
$this
->
_pageSize
=
null
;
}
else
{
$value
=
(
int
)
$value
;
if
(
count
(
$this
->
pageSizeLimit
)
===
2
&&
isset
(
$this
->
pageSizeLimit
[
0
],
$this
->
pageSizeLimit
[
1
]))
{
if
(
$validatePageSize
&&
count
(
$this
->
pageSizeLimit
)
===
2
&&
isset
(
$this
->
pageSizeLimit
[
0
],
$this
->
pageSizeLimit
[
1
]))
{
if
(
$value
<
$this
->
pageSizeLimit
[
0
])
{
$value
=
$this
->
pageSizeLimit
[
0
];
}
elseif
(
$value
>
$this
->
pageSizeLimit
[
1
])
{
...
...
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