使用symfony2在数据库中插入值

时间:2015-05-11 19:38:41

标签: php symfony

我想在我的表格中插入值,但它对我不起作用,我该怎么办?

java.lang.NumberFormatException: Invalid double: "13,170.00"

1 个答案:

答案 0 :(得分:0)

一个可能的错误来源是控制器无法找到Product实体。通过添加使用MyAppLibraryBundle \ Entity \ Product;声明(假设它在该路径中)可以找到实体。如果这不是答案,请发布您收到的错误消息。

//with this line:
use MyAppLibraryBundle\Entity\Product;

class DefaultController extends Controller
{
....

public function createAction()
{
    $product = new Product();
    $product->setName('A Foo Bar');
    $product->setPrice('19.99');
    $product->setDescription('Lorem ipsum dolor');

    $em = $this->getDoctrine()->getManager();
    $em->persist($product);
    $em->flush();

    return new Response('Id du produit créé : '.$product->getId());
}

}
相关问题