Zend_View-Helpers-Cycle.xml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 <code>Cycle</code> 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 <code>assign(array $data)</code> function
  13. </para>
  14. <programlisting role="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 role="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>To use two cycles you have to specify the names of cycles. Just set second parameter in cycle method.
  42. <code>$this->cycle(array("#F0F0F0","#FFFFFF"),'cycle2')</code>. You can also use setName($name) function.
  43. </para>
  44. </example>
  45. <programlisting role="php"><![CDATA[
  46. <?php foreach ($this->books as $book):?>
  47. <tr style="background-color:<?php echo $this->cycle(array("#F0F0F0",
  48. "#FFFFFF"))
  49. ->next()?>">
  50. <td><?php echo $this->cycle(array(1,2,3),'number')->next()?></td>
  51. <td><?php echo $this->escape($book['author'])?></td>
  52. </tr>
  53. <?php endforeach;?>
  54. ]]></programlisting>
  55. </sect3>
  56. <!--
  57. vim:se ts=4 sw=4 et:
  58. -->