symfony2:更新数据错误


symfony2: update data error

我正在尝试使用form.更新数据库中的数据

控制器是:

public function addAction($id) {
  $em = $this->getDoctrine()->getEntityManager();
  $product = $em->getRepository('AcmeStoreBundle:Product')->find($id);
  if (!$product) {
    $product = new Product();
  }
  $form = $this->createForm(new PageAdd(), $product);
  $request = $this->getRequest();
  if ($request->getMethod() == 'POST') {
     $form->bindRequest($request);
     $name=$this->get('request')->request->get('name');
     $price=$this->get('request')->request->get('price');
     $description=$this->get('request')->request->get('description'); 
     if ($form->isValid()) {
        $product->setName($name);
        $product->setPrice($price);
        $product->setDescription($description);    
        $em->persist($product);
        $em->flush();
        /*Llamando a la plantilla de listados*/
        $product = $em->getRepository('AcmeStoreBundle:Product')->findAll();
        /*Enviando los datos a la plantilla y Renderizandola*/
        return $this->render('AcmeStoreBundle:Default:pageadd.html.twig', array('Product' => $product));
     }
  }
  return $this->render('AcmeStoreBundle:Default:show.html.twig', array('form' => $form->createView(), 'product' => $product));
}

show.html.twig文件为

<form action="{{ path('Product_add',{'id':product.id}) }}"
{{ form_enctype(form) }}>
            {{ form_errors(form) }}
            {{ form_rest(form) }}
               <input type="submit" value="Save This Page" class="savebutton" />
         </form>

它给我错误

AcmeStoreBundle中不存在对象"Acme''StoreBundle''Entity''Product"的方法"id":默认值:第2行的show.html.twig500内部服务器错误-Twig_Error_Runtime

这意味着产品实体中缺少getId()方法。

public function getId()
{
  return $this->id;
}