0

コントローラーで getName() にアクセスしようとしていますが、機能していません。

これは機能しません:

 $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..."

これは機能します:

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

なんで?

4

5 に答える 5

5

findBy は、オブジェクトではなく配列を返します。findOneByのことですか?

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

于 2013-06-07T19:21:15.750 に答える
0

これを置き換えます:

$supplier = $em->getRepository('WICSupplierBundle:Supplier')->findBy(array('account'=>$account_id, 'id'=>$id));
$supplierName = $supplier->getName();

と:

$supplier = $em->getRepository('WICSupplierBundle:Supplier')->findOneBy(array('account'=>$account_id, 'id'=>$id));
$supplierName = $supplier->getName(); 
于 2014-08-07T05:35:08.133 に答える
-2

私は周りを見回しました、私はあなたが複数の配列を使う必要があると思います、

$supplier = $em->getRepository('WICSupplierBundle:Supplier')
->findBy(
array('account'=>$account_id),  ##  array 1 
array('id'=>$id)                ##  array 2
);

$supplierName = $supplier->getName(); 更新:ドキュメント
をもう一度 読み直した後、2 番目の配列が並べ替え用であることに気付きました。

于 2013-06-07T21:24:33.543 に答える