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