paginator-control.xml 4.4 KB

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