Zend Framework implementation of the message this page function (with demo source download) _php instance

Source: Internet
Author: User
Tags zend zend framework

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.