我是新來Symfony和我試圖使用從列表中傳遞一個對象到一個新的頁面:Symfony3標識符ID缺少的appbundle 實體的查詢
<a href="{{ path('fooUpdate', { 'id': item.id }) }}">Update</a>
名單美孚對象的({% for item in list %})
優良,對象從數據庫滿載,但鏈接不會因爲這個學說錯誤的工作:
The identifier id is missing for a query of AppBundle\Entity\Foo
這裏是Foo類:
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
這裏是控制器的方法:
/**
* @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
));
}
鏈接本身看起來是工作,因爲錯誤的網址是:
http://127.0.0.1:8000/foo/fooUpdate/?id=1
所以我缺少什麼?
此外,有沒有辦法使用POST來做到這一點,所以ID不會出現在URL?
謝謝!它的工作,但任何想法如何通過郵政做到這一點? – Eduardo
假設您有表單或類似的信息發送您的發佈數據。您必須將您的路線配置爲* @Method({「POST」}),然後在您的控制器操作中讓您發佈變量。 Saludos – Hokusai