title: How to list oneToMany using ZF2 and Doctrine
body: <p>I am trying to create listAction() to list all data from an Entity. I have used the example listed in <a href="https://stackoverflow.com/questions/22648186/update-two-tables-from-one-form-with-zf2-and-doctrine/">Update two tables from one form with ZF2 and Doctrine</a> and <a href="https://github.com/doctrine/DoctrineModule/blob/master/docs/hydrator.md" rel="nofollow noreferrer">Hydrator</a> to create my study case.</p>
  
  <p>I am able to list the parent data but the data from child entity I just dont know how.</p>
  
  <p>Just don't  know how to create the list.phtml do show the child data entities.</p>
  
  <p>There is an example anywhere?</p>
  
  <p><strong>ProfileController.php</strong> </p>
  
  <pre><code>public function updateAction()
  {
  
      // Verificar se existe parâmetro passado na rota
      $id = (int)$this-&gt;params()-&gt;fromRoute('id', 0);
  
      // Se não existe parâmetro, redirecionar para lista
      if (!$id) {
          return $this-&gt;redirect()-&gt;toRoute(
              $this-&gt;route,
              array(
                  'controller' =&gt; $this-&gt;controller,
                  'action' =&gt; 'list')
          );
      }
  
      // Get your ObjectManager from the ServiceManager
      $objectManager = $this-&gt;getServiceLocator()-&gt;get('Doctrine\ORM\EntityManager');
  
      // Create the form and inject the ObjectManager
      $form = new PerfilUpdate($objectManager);
  
      // Buscar dados na entidade and bind it to the form
      $perfil = $this-&gt;getEm()-&gt;find($this-&gt;entity, $id);
      $form-&gt;bind($perfil);
  
      $request = $this-&gt;getRequest();
  
      if ($request-&gt;isPost()) {
          $form-&gt;setData($request-&gt;getPost());
  
          if ($form-&gt;isValid()) {
              // Save the changes
              $objectManager-&gt;flush();
  
              // Redirecionar para lista de perfis
              return $this-&gt;redirect()-&gt;toRoute(
                  $this-&gt;route,
                  array(
                      'controller' =&gt; $this-&gt;controller,
                      'action' =&gt; 'list')
              );
  
          }
      }
  
      return array(
          'form' =&gt; $form,
          'id' =&gt; $id,
      );
  }
  </code></pre>
  
  <p><strong>update.phtml</strong></p>
  
  <pre><code>&lt;?php
  $title = $this-&gt;translate('Editar Perfil');
  $this-&gt;headTitle($title);
  ?&gt;
  &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
          &lt;div class="panel-title"&gt;
              &lt;?php echo $title ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;?php
      $form = $this-&gt;form;
  
      $form-&gt;setAttribute('action',
          $this-&gt;url(
              'tenil-user/default',
              array(
                  'controller' =&gt; 'profile',
                  'action' =&gt; 'update',
                  'id' =&gt; $this-&gt;id
              ))
      );
  
      $form-&gt;prepare();
  
      echo $this-&gt;form()-&gt;openTag($form);
      ?&gt;
      &lt;div class="panel-body"&gt;
          &lt;?php
  
          $id = $form-&gt;get('perfil')-&gt;get('id');
          echo $this-&gt;formHidden($id);
  
          $security = $form-&gt;get('security');
          echo $this-&gt;formElement($security);
  
          echo '&lt;div class="form-group"&gt;';
          $nome = $form-&gt;get('perfil')-&gt;get('nome');
          echo $this-&gt;formLabel($nome);
          echo '&lt;div class="col-md-10"&gt;';
          echo $this-&gt;formInput($nome);
          echo '&lt;/div&gt;';
          echo '&lt;/div&gt;';
  
          echo '&lt;div class="form-group"&gt;';
          $sobrenome = $form-&gt;get('perfil')-&gt;get('sobrenome');
          echo $this-&gt;formLabel($sobrenome);
          echo '&lt;div class="col-md-10"&gt;';
          echo $this-&gt;formInput($sobrenome);
          echo '&lt;/div&gt;';
          echo '&lt;/div&gt;';
  
          echo '&lt;div class="form-group"&gt;';
          $apelido = $form-&gt;get('perfil')-&gt;get('apelido');
          echo $this-&gt;formLabel($apelido);
          echo '&lt;div class="col-md-10"&gt;';
          echo $this-&gt;formInput($apelido);
          echo '&lt;/div&gt;';
          echo '&lt;/div&gt;';
  
          ?&gt;
      &lt;/div&gt;
  
      &lt;div class="panel-footer"&gt;
          &lt;div class="clearfix"&gt;
              &lt;div class="pull-right"&gt;
                  &lt;?php
                  $submit = $form-&gt;get('submit');
                  $submit-&gt;setAttribute('class', 'btn btn-default');
                  echo $this-&gt;formSubmit($submit);
                  ?&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;?php
  
  
      echo $this-&gt;form()-&gt;closeTag();
  
      foreach ($form as $element) {
          echo $this-&gt;formElementErrors($element);
      }
  ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>When I submit the form, whith the changes, the <code>$id</code> param aways is set to null, then <code>if (!$id)</code> is true. So the data is never updated.</p>