In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what are the very useful Zend Framework paging classes". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Here to share with you a very useful Zend Framework paging class
The specific effect can be seen in the paging effect of this site, and the CSS style can be changed according to the personal design sense.
Here I will give an example of how to use this class, as follows:
IndexController.php, write the following code in Action:
The copy code is as follows:
Protected $_ curPage = 1; / / default to the first page
Const PERPAGENUM = 4; / / number of entries per page
Public function indexAction ()
{
/ / $this- > _ blogModel instantiated blogModel
/ / $rows-> get the total number of entries of the displayed data
$rows = $this- > _ blogModel- > getTotalRows ()
If ($pageNum = $this- > getRequest ()-> getParam ('page')) {
/ / if a value is passed in, overwrite the initial first page
$this- > _ curPage = $pageNum
}
/ / transfer the data from the data table to the front end
$this- > view- > blogInfo = $this- > _ blogModel- > getBlogInfo (
Self::PERPAGENUM, ($this- > _ curPage-1) * self::PERPAGENUM
);
/ / instantiate the paging class and pass it to the front end
$this- > view- > pagebar = $this- > displayPageBar ($rows)
}
Private function displayPageBar ($totalRows)
{
$Pager = new Zend_Pagination ($totalRows,self::PERPAGENUM)
Return $Pager- > getNavigation ()
}
Models/Blog.php, write the following code:
The copy code is as follows:
Public function getBlogInfo ($perPageNum = NULL, $limit = NULL)
{
Return $this- > fetchAll ('1 = 1 perPageNum, 'blog_id desc', $perPageNum, $limit)
-> toArray ()
}
Public function getTotalRows ($where = '1cm 1')
{
Return $this- > fetchAll ($where)-> count ()
}
Index.phtml, write the following code:
The copy code is as follows:
Pagebar;? >
At this point, you can see the effect. If you want to pursue a better page effect, please modify the paging category according to your personal preference. I will not give a detailed example here.
The copy code is as follows:
Class Zend_Pagination
{
Private $_ navigationItemCount = 6; / / the navigation bar shows the total number of navigation pages
Private $_ pageSize = null; / / items per page
Private $_ align = "right"; / / location of the navigation bar
Private $_ itemCount = null; / / Total projects
Private $_ pageCount = null; / / Total pages
Private $_ currentPage = null; / / current page
Private $_ front = null; / / Front-end Controller
Private $_ PageParaName = "page"; / / Page parameter name
Private $_ firstPageString = "|"; / / characters displayed on the previous page in the navigation bar
Private $_ previousPageString = "|"; / / characters displayed on the last page of the navigation bar
Private $_ splitString = "|"; / / the spacer between the numbers on the page
Public function _ _ construct ($itemCount, $pageSize)
{
If (! is_numeric ($itemCount) | | (! is_numeric ($pageSize) {
Throw new Exception ("Pagination Error:not Number")
}
$this- > _ itemCount = $itemCount
$this- > _ pageSize = $pageSize
$this- > _ front = Zend_Controller_Front::getInstance ()
$this- > _ pageCount = ceil ($itemCount/$pageSize); / / Total number of pages
$page = $this- > _ front- > getRequest ()-> getParam ($this- > _ PageParaName)
If (empty ($page) | | (! is_numeric ($page) {
/ / empty or non-numeric, set the current page to 1
$this- > _ currentPage = 1
} else {
If ($page
< 1) { $page = 1; } if ($page >$this- > _ pageCount) {
$page = $this- > _ pageCount
}
$this- > _ currentPage = $page
}
}
Public function getCurrentPage ()
{
Return $this- > _ currentPage
}
Public function getNavigation ()
{
$navigation =''
/ / which column is the current page in?
$pageCote = ceil ($this- > _ currentPage / ($this- > _ navigationItemCount-1))-1
/ / Total Page column
$pageCoteCount = ceil ($this- > _ pageCount / ($this- > _ navigationItemCount-1))
/ / start page in the paging bar
$pageStart = $pageCote * ($this- > _ navigationItemCount-1) + 1
/ / terminate the page in the paging bar
$pageEnd = $pageStart + $this- > _ navigationItemCount-1
If ($this- > _ pageCount
< $pageEnd) { $pageEnd = $this->_ pageCount
}
$navigation. = "Total: {$this- > _ itemCount} {$this- > _ pageCount} pages\ n"
If ($pageCote > 0) {/ / Home navigation
$navigation. ='_ currentPage! = 1) {/ / previous page navigation
$navigation. ='_ previousPageString. ''
}
While ($pageStart _ currentPage) {
Navigation. = "$pageStart". $this- > _ splitString
} else {
$navigation. ='_ splitString
}
$pageStart++
}
If ($this- > _ currentPage! = $this- > _ pageCount) {/ / next page navigation
$navigation. ='_ nextPageString
}
If ($pageCote
< $pageCoteCount-1) { //未页导航 $navigation .= 'getCurrentPage()==$i){ $selected = "selected"; } else { $selected = ""; } $navigation .= '_navigationItemCount; } public function setNavigationItemCoun($navigationCount) { if(is_numeric($navigationCount)) { $this->_ navigationItemCount = $navigationCount
}
}
Public function setFirstPageString ($firstPageString)
{
$this- > _ firstPageString = $firstPageString
}
Public function setPreviousPageString ($previousPageString)
{
$this- > _ previousPageString = $previousPageString
}
Public function setNextPageString ($nextPageString)
{
$this- > _ nextPageString = $nextPageString
}
Public function setLastPageString ($lastPageString)
{
$this- > _ lastPageString = $lastPageString
}
Public function setAlign ($align)
{
$align = strtolower ($align)
If ($align = = "center") {
$this- > _ align = "center"
} elseif ($align = = "right") {
$this- > _ align = "right"
} else {
$this- > _ align = "left"
}
}
Public function setPageParamName ($pageParamName)
{
$this- > _ PageParaName = $pageParamName
}
Public function getPageParamName ()
{
Return $this- > _ PageParaName
}
Private function createHref ($targetPage = null)
{
$params = $this- > _ front- > getRequest ()-> getParams ()
$module = $params ["module"]
$controller = $params ["controller"]
$action = $params ["action"]
$targetUrl = $this- > _ front- > getBaseUrl ()
. "/ $module/$controller/$action"
Foreach ($params as $key = > $value)
{
If ($key! = "controller" & & $key! = "module"
& & $key! = "action" & & $key! = $this- > _ PageParaName) {
$targetUrl. = "/ $key/$value"
}
}
If (isset ($targetPage)) {/ / specify the target page
$targetUrl. = "/ $this- > _ PageParaName/$targetPage"
} else {
$targetUrl. = "/ $this- > _ PageParaName/"
}
Return $targetUrl
}
}
Here's a brief review of limit offset in Mysql.
Suppose there are 13 pieces of data in the database table blog.
Statement 1:select * from blog limit 9,4
Statement 2:select * from blog limit 4 offset 9
/ / statements 1 and 2 both return rows 10, 11, 12, 13 of table blog
The 9 in statement 1 indicates that it starts at the tenth row of the table and returns four rows.
/ / 4 in statement 2 returns 4 rows, and offset 9 starts from the tenth row of the table
The following statement shows the paging effect:
Statement 3:select * from blog limit ($this- > _ curPage-1) * self::PERPAGENUM, self::PERPAGENUM
Statement 4:select * from blog limit self::PERPAGENUM offset ($this- > _ curPage-1) * self::PERPAGENUM
This is the end of the content of "what are the very useful Zend Framework paging classes". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.