paginator-control.xml 4.4 KB

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