2012-10-28 61 views

回答

-1
if ($id == 0) { 
    $task = new Task(); 
    } 

您的ID参数默认为0,并且创建新的任务而不是更新现有的tast。

hello_index: 
    pattern: /hello/index/{id} 
    defaults: { _controller: AcmeHelloBundle:hello:index, id:0 } 

您应该单独创建和编辑/更新操作并为每个操作创建一个路由。

http://symfony.com/doc/2.0/book/doctrine.html#updating-an-object

1

你的问题的正确答案是使用合并方法,而不是坚持。例如: -

$your_entity = $form->getData(); 
$this->em->merge($your_entity); // MERGE not PERSIST 
$this->em->flush(); 

您可以在official documentation

干杯阅读更多关于合并方法,