Php Symfony2,Doctrine2,更新实体
我想通过对控制器的ajax调用将一个实体更新到db中。然而,我只知道如何使用Symfony的表单更新实体。目前,我有一个表单,它将被jQuery方法附加,并通过ajax提交,但我不知道在控制器中该做什么 阿贾克斯: 现在在我的控制器上:Php Symfony2,Doctrine2,更新实体,php,jquery,ajax,symfony,Php,Jquery,Ajax,Symfony,我想通过对控制器的ajax调用将一个实体更新到db中。然而,我只知道如何使用Symfony的表单更新实体。目前,我有一个表单,它将被jQuery方法附加,并通过ajax提交,但我不知道在控制器中该做什么 阿贾克斯: 现在在我的控制器上: /** * @Route("/edit/", name="containers_edit", defaults={"_format" = "json"}) */ public function editCtr(Request $request) {
/**
* @Route("/edit/", name="containers_edit", defaults={"_format" = "json"})
*/
public function editCtr(Request $request) {
$ctrno = $request->get('ctrno');
$refno = $request->get('refno');
$em = $this->getDoctrine()->getManager()->getRepository('Bundle:Ref');
// I want to access in the database to find the 'refno' and update the 'ctrno',
// something like:
// $entity = $em->findRefno($refno);
// $entity->setCtrno($ctrno);
// $em->flush();
return new Response(json_encode($entity));
}
对此有什么建议吗?检查评论中的链接,它提供了您需要的一切 只需添加一件事,在代码中您需要更改方法名
editCtr()
到editCtrAction()
控制器类中的所有方法都是“actions”。希望这能有所帮助。就像有普通表单一样,只是别忘了在jQuery中序列化数据。看看这里——到底是什么不起作用?
/**
* @Route("/edit/", name="containers_edit", defaults={"_format" = "json"})
*/
public function editCtr(Request $request) {
$ctrno = $request->get('ctrno');
$refno = $request->get('refno');
$em = $this->getDoctrine()->getManager()->getRepository('Bundle:Ref');
// I want to access in the database to find the 'refno' and update the 'ctrno',
// something like:
// $entity = $em->findRefno($refno);
// $entity->setCtrno($ctrno);
// $em->flush();
return new Response(json_encode($entity));
}