1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="learning.paginator.control">
4 <title>Pagination Control and ScrollingStyles</title>
7 Rendering the items for a page on the screen has been a good start. In the code
8 snippets in previous section we have also seen the
9 <methodname>setCurrentPageNumber()</methodname> method to set the active page number. The
10 next step is to navigate through your pages. To do this, Paginator provides you with two
11 important tools: the ability to render the Paginator with help of a View Partial, and
12 support for so-called ScrollingStyles.
16 The View Partial is a small view script that renders the Pagination controls, such as
17 buttons to go to the next or previous page. Which pagination controls are rendered depends
18 on the contents of the view partial. Working with the view partial requires that you have
19 set up <classname>Zend_View</classname>. To get started with the pagination control, create
20 a new view script somewhere in your view scripts path. You can name it anything you want,
21 but we'll call it "controls.phtml" in this text. The reference manual contains various
22 examples of what might go in the view script. Here is one example.
25 <programlisting language="php"><![CDATA[
26 <?php if ($this->pageCount): ?>
27 <!-- First page link -->
28 <?php if (isset($this->previous)): ?>
29 <a href="<?php echo $this->url(array('page' => $this->first)); ?>">
33 <span class="disabled">First</span> |
36 <!-- Previous page link -->
37 <?php if (isset($this->previous)): ?>
38 <a href="<?php echo $this->url(array('page' => $this->previous)); ?>">
42 <span class="disabled">< Previous</span> |
45 <!-- Next page link -->
46 <?php if (isset($this->next)): ?>
47 <a href="<?php echo $this->url(array('page' => $this->next)); ?>">
51 <span class="disabled">Next ></span> |
54 <!-- Last page link -->
55 <?php if (isset($this->next)): ?>
56 <a href="<?php echo $this->url(array('page' => $this->last)); ?>">
60 <span class="disabled">Last</span>
68 The next step is to tell <classname>Zend_Paginator</classname> which view partial can be
69 used to render the navigation controls. Put the following line in your application's
73 <programlisting language="php"><![CDATA[
74 Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
78 The last step is probably the easiest. Make sure you have assigned your Paginator object
79 to the a script (NOT the 'controls.phtml' script!). The only thing left to do is echo the
80 Paginator in the view script. This will automatically render the Paginator using the
81 PaginationControl view helper. In this next example, the Paginator object has been assigned
82 to the 'paginator' view variable. Don't worry if you don't fully get how it all works yet.
83 The next section will feature a complete example.
86 <programlisting language="php"><![CDATA[
87 <?php echo $this->paginator; ?>
91 <classname>Zend_Paginator</classname>, together with the 'controls.phtml' view script you
92 wrote, makes sure your Paginator navigation is rendered properly. In order to decide
93 which page numbers need to be displayed on screen, Paginator uses so-called ScrollingStyles.
94 The default style is called "Sliding", which is similar to the way Yahoo's search result
95 navigation works. To mimick Google's ScrollingStyle, use the Elastic style.
96 You can set a default ScrollingStyle with the static
97 <methodname>setDefaultScrollingStyle()</methodname> method, or you can specify a
98 ScrollingStyle dynamically when rendering the Paginator in your view script. This requires
99 manual invocation of the view helper in your view script.
102 <programlisting language="php"><![CDATA[
103 // $this->paginator is a Paginator object
104 <?php echo $this->paginationControl($this->paginator, 'Elastic', 'controls.phtml'); ?>
108 For a list of all available ScrollingStyles, see the reference manual.