paginator-control.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <classname>Zend_View</classname>. To get started with the pagination control, create
  18. a new view script somewhere in your view scripts path. You can name it anything you want,
  19. but we'll call it "controls.phtml" in this text. The reference manual contains various
  20. examples of what might 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 <classname>Zend_Paginator</classname> which view partial can be
  61. used to render the navigation controls. Put the following line in your application's
  62. bootstrap file.
  63. </para>
  64. <programlisting language="php"><![CDATA[
  65. Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
  66. ]]></programlisting>
  67. <para>
  68. The last step is probably the easiest. Make sure you have assigned your Paginator object
  69. to the a script (NOT the 'controls.phtml' script!). The only thing left to do is echo the
  70. Paginator in the view script. This will automatically render the Paginator using the
  71. PaginationControl view helper. In this next example, the Paginator object has been assigned
  72. to the 'paginator' view variable. Don't worry if you don't fully get how it all works yet.
  73. The next section will feature a complete example.
  74. </para>
  75. <programlisting language="php"><![CDATA[
  76. <?php echo $this->paginator; ?>
  77. ]]></programlisting>
  78. <para>
  79. <classname>Zend_Paginator</classname>, together with the 'controls.phtml' view script you
  80. wrote, makes sure your Paginator navigation is rendered properly. In order to decide
  81. which page numbers need to be displayed on screen, Paginator uses so-called ScrollingStyles.
  82. The default style is called "Sliding", which is similar to the way Yahoo's search result
  83. navigation works. To mimick Google's ScrollingStyle, use the Elastic style.
  84. You can set a default ScrollingStyle with the static
  85. <methodname>setDefaultScrollingStyle()</methodname> method, or you can specify a
  86. ScrollingStyle dynamically when rendering the Paginator in your view script. This requires
  87. manual invocation of the view helper in your view script.
  88. </para>
  89. <programlisting language="php"><![CDATA[
  90. // $this->paginator is a Paginator object
  91. <?php echo $this->paginationControl($this->paginator, 'Elastic', 'controls.phtml'); ?>
  92. ]]></programlisting>
  93. <para>
  94. For a list of all available ScrollingStyles, see the reference manual.
  95. </para>
  96. </sect1>