I am just starting out with Symfony2 . Rather than having to learn twig, I decided to implement my forms in php instead. I followed the instructions in The Book, as follows:
in the controller:
public function editAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('MyBundle:MyEntity')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find MyEntity entity.');
}
$editForm = $this->createForm(new MyEntityType(), $entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('MyBundle:MyEntity:edit.html.php' array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView()
));
}
and in edit.html.php:
<form action="<?php echo $view['router']->generate('myentity_update', array('id'=>$entity->getId()))?>" method="post" <?php echo $view['form']->enctype($editForm) ?>>
<?php echo $view['form']->widget($editForm)?>
<p>
<button type="submit">Save Changes</button>
</p>
</form>
<ul class="record_actions">
<li>
<a href="<?php $view['router']->generate('myentity') ?>">
Back to the list
</a>
</li>
<li>
<form action="<?php $view['router']->generate('myentity_delete', array('id'=>$entity->getId()) ) ?>" method="post">
<?php echo $view['form']->widget($deleteForm)?>
<button type="submit">Delete</button>
</form>
</li>
when I try to display the form I get error: Notice: Undefined variable editForm
As far as I'm aware, I have followed the instructions exactly as they are given in The Book. I have tried replacing $editForm with $form in the action and template or replacing $editForm with edit_form in the template - needless to say, neither of these worked.
I would very much appreciate any suggestions as to what I should try next (or I may have to resign myself to learning twig, as at least the instructions for that seem to be correct).