title: Edit form in Symfony2
body: <p>I am not using Doctrine's generator because I think the code is ugly, thus I am trying to make it work my <code>editAction</code> and render the form in my <code>edit.html.twig</code> page, but I can not make it work. I tried to follow other examples given by other answers but they did not work either.</p>
  
  <p>First, my <code>editAction</code>.</p>
  
  <pre><code>public function editAction($id, Request $request)
  {
      $manager = $this-&gt;getDoctrine()-&gt;getManager();
      $entity = $manager-&gt;getRepository('PanelBundle:Material')-&gt;find($id);
  
      if (!$entity) {
          throw $this-&gt;createNotFoundException('O material procurado não está cadastrado');
      }
  
      $form = $this-&gt;createForm(new MaterialType());
      $form-&gt;handleRequest($request);
  
      if ($request-&gt;getMethod() == 'POST') {
          $form-&gt;submit($request);
  
          if ($form-&gt;isValid()) {
              $manager-&gt;merge($entity);
              $manager-&gt;flush();
  
              $this-&gt;addFlash('success', 'Material alterado');
  
              return $this-&gt;redirect($this-&gt;generateUrl('panel_materials'));
          }
      }
  
      return $this-&gt;render('PanelBundle:Material:edit.html.twig', array(
          'entity' =&gt; $entity
      ));
  }
  </code></pre>
  
  <p>Now, my Twig</p>
  
  <pre><code>{% extends '::layout.html.twig' %}
  
  {% block title %}Editar {{ entity.name }}{% endblock %}
  
  {% block body %}
      &lt;div class="container"&gt;
          &lt;h1&gt;Editar {{ entity.name }}&lt;/h1&gt;
  
          &lt;form action="{{ path('panel_edit_material', { 'id': entity.id }) }}" method="POST"&gt;
              &lt;div class="form-group"&gt;
                  {{ form_row(entity.name) }}
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  {{ form_row(entity.description) }}
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  {{ form_row(entity.quantity) }}
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  {{ form_row(entity.price) }}
              &lt;/div&gt;
  
              {{ form_rest(form) }}
  
              &lt;button type="submit" class="btn btn-success"&gt;Alterar&lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p>Two things: if I remove the <code>{ 'id': entity.id }</code>, an error is shown saying a mandatory field is missing, if I let it like it is now, it says <code>searchAndRenderBlock() must be an instance of Symfony\Component\Form\FormView</code>, and if instead of returning <code>$entity</code> in controller, and return <code>$form-&gt;createView()</code>, the error says <code>FormView could not be converted to string</code></p>