title: zend 2 + Doctrine 2 returned checkbox values
body: <p>I am using zend 2 and doctrine 2</p>
  
  <p>I am not clear how to return and populate a database with returned values from a checkbox. The values should return multiple entries for the table.</p>
  
  <p>I cannot find any documentation/articles on how to render or use a check box; so, I would really appreciate advice or sample code on this.</p>
  
  <p>I have enclosed my class below. I believe that the problem is occurring in my entity class: i.e I am not properly using the getter/setter for an array collection, consequently I keep getting the error message, from my returned postform, that my returned values are empty. </p>
  
  <p>Here is my code: </p>
  
  <p><strong>My mysql table:</strong> </p>
  
  <pre><code>CREATE TABLE workers_timetable(
  id MEDIUMINT UNSIGNED NOT NULL, 
  timesId MEDIUMINT UNSIGNED NOT NULL,
  INDEX (id ,timesId ), 
  INDEX times_id (timesId, id ) 
  
  ); 
  </code></pre>
  
  <p><strong>My Class;</strong> </p>
  
  <pre><code>&lt;?php
  
  namespace Workers\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Zend\InputFilter\InputFilter;
  use Zend\InputFilter\Factory as InputFactory;
  use Zend\InputFilter\InputFilterAwareInterface;
  use Zend\InputFilter\InputFilterInterface; 
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  
  
  /**
   *
   * @ORM\Entity
   * @ORM\Table(name="workers_timetable")
   * @property int $timesId
   */
  class WorkersAvailabilityTimeTable {
  
     /**
       * @ORM\Id
       * @ORM\Column(type="integer");
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @ORM\Column(type="integer");
       */
      protected $timesId;
  
  
  
  
      public function __construct()
      {
          $this-&gt;timesId = new ArrayCollection();
      }
  
  
     public function getId()
      {
          return $this-&gt;id;
      } 
  
  
  
     public function addTimesId(Collection $timesId)
      {
          foreach ($timesId as $timesId) {
              $this-&gt;setTimesId($this);
              $this-&gt;timesId-&gt;add($timesId);
          }
      }
  
      public function setTimesId()
      {
          return $this-&gt;timesId;
      }
  
  
      public function removeTimesId(Collection $timesId)
      {
          foreach ($timesId as $timesId) {
              $this-&gt;setTimesId(null);
              $this-&gt;timesId-&gt;removeElement($timesId);
          }
      }
  
      public function getTimesId()
      {
          return $this-&gt;timesId;
      }
  
  
      //put your code here
  }
  </code></pre>
  
  <p><strong>my fieldSet class</strong></p>
  
  <pre><code>&lt;?php
  
  namespace Workers\Form\Fieldset;
  
  use Workers\Entity\WorkersAvailabilityTimeTable;
  use Doctrine\Common\Persistence\ObjectManager;
  use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
  use Zend\Form\Fieldset;
  use Zend\InputFilter\InputFilterProviderInterface;
  
  
  
  class WorkersAvailabilityTimeTableFieldset extends Fieldset implements InputFilterProviderInterface
  {
     public function __construct(ObjectManager $objectManager)
      {
          parent::__construct('WorkerTimeTable');
  
  
          $this-&gt;setHydrator(new DoctrineHydrator($objectManager, 'Workers\Entity\WorkersAvailabilityTimeTable'))
               -&gt;setObject(new WorkersAvailabilityTimeTable());
  
  
          $this-&gt;add(array(
              'name' =&gt; 'id',
              'type' =&gt; 'Zend\Form\Element\Hidden',
          ));
  
           $this-&gt;add(array(
              'type' =&gt; 'Zend\Form\Element\MultiCheckbox',
              'name' =&gt; 'timesIds',
              'options' =&gt; array(
                  'label' =&gt; 'Please Select Your Availablity',
                  'value_options' =&gt; array(
  
                      '1'  =&gt;'mon',
                      '2' =&gt;'tues'
     ),
              ),
              'attributes' =&gt; array(
                  'value' =&gt; '1' //set checked to '1'
              )
          ));
       )
  </code></pre>