<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect3 id="zend.view.helpers.initial.cycle">

    <title>Cycle Helper</title>

    <para>
      The <code>Cycle</code> helper is used to alternate a set of values.
    </para>

    <example id="zend.view.helpers.initial.cycle.basicusage">

        <title>Cycle Helper Basic Usage</title>

        <para>
            To add elements to cycle just specify them in constructor
            or use <code>assign(array $data)</code> function
        </para>

        <programlisting language="php"><![CDATA[
<?php foreach ($this->books as $book):?>
  <tr style="background-color:<?php echo $this->cycle(array("#F0F0F0",
                                                            "#FFFFFF"))
                                              ->next()?>">
  <td><?php echo $this->escape($book['author']) ?></td>
</tr>
<?php endforeach;?>

// Moving in backwards order and assign function
$this->cycle()->assign(array("#F0F0F0","#FFFFFF"));
$this->cycle()->prev();
?>
]]></programlisting>

        <para>
            The output
        </para>

        <programlisting language="php"><![CDATA[
<tr style="background-color:'#F0F0F0'">
   <td>First</td>
</tr>
<tr style="background-color:'#FFFFFF'">
   <td>Second</td>
</tr>
]]></programlisting>

    </example>

    <example id="zend.view.helpers.initial.cycle.advanceusage">

        <title>Working with two or more cycles</title>

       <para>
           To use two cycles you have to specify the names of cycles. Just set second parameter in
           cycle method. <code>$this->cycle(array("#F0F0F0","#FFFFFF"),'cycle2')</code>. You can
           also use setName($name) function.
        </para>

    </example>

    <programlisting language="php"><![CDATA[
<?php foreach ($this->books as $book):?>
  <tr style="background-color:<?php echo $this->cycle(array("#F0F0F0",
                                                            "#FFFFFF"))
                                              ->next()?>">
  <td><?php echo $this->cycle(array(1,2,3),'number')->next()?></td>
  <td><?php echo $this->escape($book['author'])?></td>
</tr>
<?php endforeach;?>
]]></programlisting>

</sect3>
<!--
vim:se ts=4 sw=4 et:
-->
