Zend_View-Helpers-Cycle.xml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.view.helpers.initial.cycle">
  4. <title>Cycle Helper</title>
  5. <para>
  6. The <classname>Cycle</classname> helper is used to alternate a set of values.
  7. </para>
  8. <example id="zend.view.helpers.initial.cycle.basicusage">
  9. <title>Cycle Helper Basic Usage</title>
  10. <para>
  11. To add elements to cycle just specify them in constructor
  12. or use <methodname>assign(array $data)</methodname> function
  13. </para>
  14. <programlisting language="php"><![CDATA[
  15. <?php foreach ($this->books as $book):?>
  16. <tr style="background-color:<?php echo $this->cycle(array("#F0F0F0",
  17. "#FFFFFF"))
  18. ->next()?>">
  19. <td><?php echo $this->escape($book['author']) ?></td>
  20. </tr>
  21. <?php endforeach;?>
  22. // Moving in backwards order and assign function
  23. $this->cycle()->assign(array("#F0F0F0","#FFFFFF"));
  24. $this->cycle()->prev();
  25. ?>
  26. ]]></programlisting>
  27. <para>
  28. The output
  29. </para>
  30. <programlisting language="php"><![CDATA[
  31. <tr style="background-color:'#F0F0F0'">
  32. <td>First</td>
  33. </tr>
  34. <tr style="background-color:'#FFFFFF'">
  35. <td>Second</td>
  36. </tr>
  37. ]]></programlisting>
  38. </example>
  39. <example id="zend.view.helpers.initial.cycle.advanceusage">
  40. <title>Working with two or more cycles</title>
  41. <para>
  42. To use two cycles you have to specify the names of cycles. Just set second parameter in
  43. cycle method. <command>$this->cycle(array("#F0F0F0","#FFFFFF"),'cycle2')</command>. You
  44. can also use setName($name) function.
  45. </para>
  46. </example>
  47. <programlisting language="php"><![CDATA[
  48. <?php foreach ($this->books as $book):?>
  49. <tr style="background-color:<?php echo $this->cycle(array("#F0F0F0",
  50. "#FFFFFF"))
  51. ->next()?>">
  52. <td><?php echo $this->cycle(array(1,2,3),'number')->next()?></td>
  53. <td><?php echo $this->escape($book['author'])?></td>
  54. </tr>
  55. <?php endforeach;?>
  56. ]]></programlisting>
  57. </sect3>
  58. <!--
  59. vim:se ts=4 sw=4 et:
  60. -->