Home  >  Article  >  Backend Development  >  Zend Framework implements guestbook paging function (with demo source code download), zenddemo_PHP tutorial

Zend Framework implements guestbook paging function (with demo source code download), zenddemo_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:56:12789browse

Zend Framework implements the guestbook paging function (with demo source code download), zenddemo

This article describes how Zend Framework implements the guestbook paging function. Share it with everyone for your reference, the details are as follows:

The paging function here uses the Zend_Paginator component to implement guestbook paging... Here I also refer to the tutorial written by a PHPer in PHPCHINA

The environment I implemented and the directory arrangement of the project are based on the third tutorial. If there are friends who don’t understand the arrangement of directories, please use ZF1.6.0 or above. Please refer to the previous article. Find this tutorial...I won’t say much here..Thank you..

Step one: Find the indexAction action in our controller, that is, indexController.php. We can see that...in this action. Our related tutorials only get data...We now put this action ( Action) is rewritten into the following form. The following code (with comments):

function indexAction()
{
$message=new message();//实例化数据库类
//取到所有留言getAllMessage,getAllReMessage
//二个方法在Model(Message.php)里定义的
//取到所有回复数据
$this->view->arrReviews=$message->getAllReMessage();
$page =1;//高置默认页
$numPerPage = 3;//每页显示的条数
if(isset($_GET['page']) && is_numeric($_GET['page'])){
   $page = $_GET['page'];//取到URL传过来的页数码
}
$array=$message->getAllMessage();//取到所有留言数据
$paginator = Zend_Paginator::factory($array);
$paginator->setCurrentPageNumber($page)
    ->setItemCountPerPage($numPerPage);
$this->view->paginator = $paginator;
echo $this->view->render('header.phtml');//显示模版头文件
echo $this->view->render('message/index.phtml');//显示模版
echo $this->view->render('footer.phtml');//显示模版脚文件
}

Step 2: Get the paging style we want. Here is a HTML to set the paging style. In the Zend Framework manual, three ways of displaying paging are provided... You can take a look at them yourself The usage... is actually very simple... I used the first method. We will create a new template page pagestyle.phtml in the views/scripts/ directory. This template page is the same as the guestbook header.phtml and At the same level as footer.phtml.. Because we may use this paging method in the future.. So I will put it here..: The pagestyle.phtml code is as follows: (Note: Please add the index in your entry file here. .php defines your WEB_ROOT as a global variable, which is the root directory of your website!):

if ($this->pageCount): ?>
class="paginationControl">
 if (isset($this->previous)): ?>
 "index/index/?page=
previous; &#63;> ">< 上一页 |
 else: &#63;>
 class="disabled">< 上一页 |
 endif; &#63;>
 foreach ($this->pagesInRange as $page): &#63;>
  if ($page != $this->current): &#63;>
"index/index/&#63;page=
">$page; &#63;> |
  else: &#63;>   = $page; &#63;> |
  endif; &#63;> endforeach; &#63;>
 if (isset($this->next)): &#63;>
 "index/index/&#63;page=
next; &#63;>">下一页 >
 else: &#63;>
 class="disabled">下一页 >
 endif; &#63;>
 endif; &#63;>

Step 3: Find the index.pthml template page of the guestbook display page and change the original:

foreach($this->messages as $message): &#63;>

Replace this with

if (count($this->paginator)): &#63;>
 $i=1; foreach ($this->paginator as $message): &#63;>

After

, we will add a paging display at the end:

= $this->paginationControl($this->paginator,
'Elastic', 'pagestyle.phtml'); &#63;>

In this way... we can see that our message pagination is complete

Click here to download the complete example code from this website.

Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.

Articles you may be interested in:

  • Environment configuration for getting started with Zend Framework and the first Hello World example (with demo source code download)
  • Summary of knowledge points for getting started with Zend Framework
  • Zend Framework 2.0 Event Manager (The EventManager) introductory tutorial
  • Zend Framework Smarty extension implementation method
  • Zend Framework routing mechanism code analysis
  • Zend Framework implements a guestbook with basic functions (with demo source code download)
  • Zend Framework implements the method of storing sessions in memcache
  • Zend Framework implements an example of multi-file upload function
  • A simple example of Zend Framework Cache usage
  • Zend Framework basic page layout analysis
  • Detailed explanation of Zend Framework smarty usage example
  • Summary of precautions related to Zend Framework custom Helper class
  • Classic tutorial for getting started with Zend Framework development

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1113721.htmlTechArticleZend Framework implements guestbook paging function (with demo source code download), zenddemo This article describes the Zend Framework implementation of guestbook Paging function method. Share it with everyone for your reference, with...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn