Lar*_*una 0 php symfony symfony-2.1
我试图在我的控制器中访问getName(),但它无法正常工作.
这DOES NOT工作:
 $supplier = $em->getRepository('WICSupplierBundle:Supplier')->findBy(array('account'=>$account_id, 'id'=>$id));
 $supplierName = $supplier->getName();
 This doesnt return the name from the db....
 I get the error: "Error: Call to a member function getName() on a non-object..."
这个DOES有效:
 $supplier = $em->getRepository('WICSupplierBundle:Supplier')->find($id);
 $supplierName = $supplier->getName();
 This returns the name from the db....
为什么?
findBy返回一个数组,而不是一个对象.你的意思是findOneBy?
http://docs.doctrine-project.org/en/2.0.x/reference/working-with-objects.html#querying