Table of Contents
Zend Framework implements the guestbook paging function (with demo source code download), zenddemo
Articles you may be interested in:
Home Backend Development PHP Tutorial 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

Jul 12, 2016 am 08:56 AM
framework zend Pagination

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');//显示模版脚文件
}

Copy after login

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;>

Copy after login

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

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

Copy after login

Replace this with

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

Copy after login
After

, we will add a paging display at the end:

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

Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Microsoft NET Framework Installation Issues Error Code 0x800c0006 Fix Microsoft NET Framework Installation Issues Error Code 0x800c0006 Fix May 05, 2023 pm 04:01 PM

.NET Framework 4 is required by developers and end users to run the latest versions of applications on Windows. However, while downloading and installing .NET Framework 4, many users complained that the installer stopped midway, displaying the following error message - " .NET Framework 4 has not been installed because Download failed with error code 0x800c0006 ". If you are also experiencing it while installing .NETFramework4 on your device then you are at the right place

How to identify Windows upgrade issues using SetupDiag on Windows 11/10 How to identify Windows upgrade issues using SetupDiag on Windows 11/10 Apr 17, 2023 am 10:07 AM

Whenever your Windows 11 or Windows 10 PC has an upgrade or update issue, you will usually see an error code indicating the actual reason behind the failure. However, sometimes confusion can arise when an upgrade or update fails without an error code being displayed. With handy error codes, you know exactly where the problem is so you can try to fix it. But since no error code appears, it becomes challenging to identify the issue and resolve it. This will take up a lot of your time to simply find out the reason behind the error. In this case, you can try using a dedicated tool called SetupDiag provided by Microsoft that helps you easily identify the real reason behind the error.

How to create custom pagination in CakePHP? How to create custom pagination in CakePHP? Jun 04, 2023 am 08:32 AM

CakePHP is a powerful PHP framework that provides developers with many useful tools and features. One of them is pagination, which helps us divide large amounts of data into several pages, making browsing and manipulation easier. By default, CakePHP provides some basic pagination methods, but sometimes you may need to create some custom pagination methods. This article will show you how to create custom pagination in CakePHP. Step 1: Create a custom pagination class First, we need to create a custom pagination class. this

PHP development: How to implement table data sorting and paging functions PHP development: How to implement table data sorting and paging functions Sep 20, 2023 am 11:28 AM

PHP development: How to implement table data sorting and paging functions In web development, processing large amounts of data is a common task. For tables that need to display a large amount of data, it is usually necessary to implement data sorting and paging functions to provide a good user experience and optimize system performance. This article will introduce how to use PHP to implement the sorting and paging functions of table data, and give specific code examples. The sorting function implements the sorting function in the table, allowing users to sort in ascending or descending order according to different fields. The following is an implementation form

SCNotification has stopped working [5 steps to fix it] SCNotification has stopped working [5 steps to fix it] May 17, 2023 pm 09:35 PM

As a Windows user, you are likely to encounter SCNotification has stopped working error every time you start your computer. SCNotification.exe is a Microsoft system notification file that crashes every time you start your PC due to permission errors and network failures. This error is also known by its problematic event name. So you might not see this as SCNotification having stopped working, but as bug clr20r3. In this article, we will explore all the steps you need to take to fix SCNotification has stopped working so that it doesn’t bother you again. What is SCNotification.e

Microsoft .NET Framework 4.5.2, 4.6, and 4.6.1 will end support in April 2022 Microsoft .NET Framework 4.5.2, 4.6, and 4.6.1 will end support in April 2022 Apr 17, 2023 pm 02:25 PM

Microsoft Windows users who have installed Microsoft.NET version 4.5.2, 4.6, or 4.6.1 must install a newer version of the Microsoft Framework if they want Microsoft to support the framework through future product updates. According to Microsoft, all three frameworks will cease support on April 26, 2022. After the support date ends, the product will not receive "security fixes or technical support." Most home devices are kept up to date through Windows updates. These devices already have newer versions of frameworks installed, such as .NET Framework 4.8. Devices that are not updating automatically may

How to use JavaScript to implement table paging function? How to use JavaScript to implement table paging function? Oct 20, 2023 pm 06:19 PM

How to use JavaScript to implement table paging function? With the development of the Internet, more and more websites use tables to display data. In some cases where the amount of data is large, the data needs to be displayed in pages to improve user experience. This article will introduce how to use JavaScript to implement table paging function and provide specific code examples. 1. HTML structure First, we need to prepare an HTML structure to host tables and paging buttons. We can use &lt;tab

Using JavaScript to implement paging display of table data Using JavaScript to implement paging display of table data Jun 16, 2023 am 10:00 AM

As data continues to grow, tabular display becomes more difficult. Most of the time, the amount of data in a table is so large that it becomes slow to load and users need to constantly browse the page to find the data they want. This article will introduce how to use JavaScript to realize paginated display of table data, making it easier for users to find the data they want. 1. Dynamically create tables. In order to make the paging function more controllable, tables need to be created dynamically. In the HTML page, add a table element similar to the one below.

See all articles