This article is an example of the Zend framework to implement the method of this page function. Share to everyone for your reference, specific as follows:
The paging function here uses the. Zend_paginator This component to implement the message this page ... I'm also here to refer to a tutorial in this area written by a phper in Phpchina.
My implementation of the bad environment and the project's directory arrangement is based on the third tutorial. If a friend doesn't understand the arrangement of the catalogue. Please use ZF1.6.0 above. Please find this tutorial in the previous article ... I don't have much to say here. Thank you..
The first step: in our controller, that is, indexcontroller.php find indexaction this action. We can see that. In this action, our tutorial is just fetching data. We now rewrite this action (action) into the following form. The following code (with annotations):
function indexaction () {$message =new message ();//Instantiate database class//Fetch all messages getallmessage, Getallremessage//Two methods defined in model (message.php) to all reply data $this->view->arrreviews= $message->
Getallremessage (); $page =1;//the default page $numPerPage = 3;//The number of bars displayed per page if (isset ($_get[' page ')) && is_numeric ($_get[' page ')) {$page = $_get [' Page '];//to the URL passed the page digital} $array = $message->getallmessage ()//Get all message data $paginator = Zend_paginator::factory ($
Array);
$paginator->setcurrentpagenumber ($page)->setitemcountperpage ($numPerPage);
$this->view->paginator = $paginator; echo $this->view->render (' header.phtml ');//display mode header file echo $this->view->render (' message/index.phtml '); Display template echo $this->view->render (' footer.phtml ');//Display template script file}
Step two: Take care of the style we want to page, here is the style of pagination in one HTML setting. In the Zend Framework Manual. Provides three ways to display pagination ... You can take a look at their usage. Actually, it's very simple. I used the first of it. We set up a new template page in the views/scripts/directory pagestyle.phtml. This template page is the same level as the message book header.phtml and footer.phtml. Because we may use this paging method later. So I put it here.:p agestyle.phtml code looks like this: (Note: Here please define your web_root as a global variable in your entry file index.php, which is your site root!):
if ($this->pagecount):?>
class= "Paginationcontrol" >
if (isset ($this->previous)):?>
" index/index/?page=
Previous?> ">< prev |
else:?>
class= "disabled" >< previous page |
endif?>
foreach ($this->pagesinrange as $page):?>
if ($page!= $this->current):?>
" Index/index/?page=
"> $page;?> |
else:?> = $page;?> |
endif?> Endforeach?>
if (isset ($this->next)):?>
"index/index/?page=
Next;?>" > Next >
else:?>
class= "Disabled" > next page >
endif;?> endif
;?>
The third step: Find the message this Display page INDEX.PTHML template page, the original:
foreach ($this->messages as $message):?>
This change
if (count ($this->paginator)):?>
$i =1; foreach ($this->paginator as $message):?>
After that, we add a page to the end of the display:
= $this->paginationcontrol ($this->paginator,
' elastic ', ' pagestyle.phtml ');?>
In this way,. We can see our message paging is done
Full instance code click here to download the site.
More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on the Zend Framework.