【问题标题】:Update Entity Form更新实体表格
【发布时间】:2014-08-31 13:50:34
【问题描述】:

当我尝试更新我的一个实体时,我得到了这个异常:

UndefinedMethodException:尝试在 /Applications/MAMP/htdocs/Seotool/src/Seotool/MainBundle/Controller/TaskController.php 第 64 行中的类“Symfony\Component\Form\Form”上调用方法“bindRequest”。

编辑操作:

/**
@Route(
 *     path = "/tasks/edit/{id}",
 *     name = "edit_task"
 * )
 * @Template()
 */
public function edit_taskAction($id, Request $request)
{

    $request = $this->get('request');

    if (is_null($id)) {
        $postData = $request->get('task');
        $id = $postData['id'];
    }

    $em = $this->getDoctrine()->getManager();
    $task = $em->getRepository('SeotoolMainBundle:Task')->find($id);
    $form = $this->createForm(new TaskType(), $task);

    if ($request->getMethod() == 'POST') {
        $form->bindRequest($request);

        if ($form->isValid()) {
            // perform some action, such as save the object to the database
            $em->flush();

            return $this->redirect($this->generateUrl('taskmanager'));
        }
    }

    return array('form' => $form->createView());

}

我的代码有什么问题?

【问题讨论】:

    标签: php symfony entity


    【解决方案1】:

    因为没有方法bindRequest。异常非常明确。如果你查看官方API,我猜你想使用handleRequest

    【讨论】:

      猜你喜欢
      • 2018-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-24
      相关资源
      最近更新 更多