I am new to symfony and I am trying to pass a object from a list to a new page using:
<a href="{{ path('fooUpdate', { 'id': item.id }) }}">Update</a>
The list ({% for item in list %}) of Foo objects is fine, the objects are fully loaded from the database, but the link does not work because of this Doctrine error:
The identifier id is missing for a query of AppBundle\Entity\Foo
Here is the Foo class:
namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="foo") */ class Foo { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue */ private $id; /** * @ORM\Column(type="string") */ private $description; //getters and setters And here is the controller method:
/** * @Route("/foo/fooUpdate/", name="fooUpdate") */ public function updateAction($id, Request $request) { $foo = $this->getDoctrine()->getRepository('AppBundle:Foo')->find($id); return $this->render('/foo/fooUpdate.html.twig', array( 'foo' => $foo )); } The link itself looks like it is working, because the URL of the error is:
http://127.0.0.1:8000/foo/fooUpdate/?id=1 So what am I missing?
Also, is there any way of doing this using POST, so the id will not appear in the URL?