Symfony getName()在控制器内部无效

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..."
Run Code Online (Sandbox Code Playgroud)

这个DOES有效:

 $supplier = $em->getRepository('WICSupplierBundle:Supplier')->find($id);
 $supplierName = $supplier->getName();
 This returns the name from the db....
Run Code Online (Sandbox Code Playgroud)

为什么?

Jes*_*ica 5

findBy返回一个数组,而不是一个对象.你的意思是findOneBy?

http://docs.doctrine-project.org/en/2.0.x/reference/working-with-objects.html#querying