0
有一種方法來連接symfony中的findBy操作的兩個結果?如果產品是由用戶創建的,我試圖將用戶對象連接到產品陣列。我的代碼:從getRepository連接結果symfony
public function indexAction()
{
$products = $this->getDoctrine()
->getRepository('AppBundle:Product')
->findById($this->getUser()->getId());
if ($products[0]->getCreatedByUser() == 1){
$userDetails = $this->getDoctrine()->getRepository('AppBundle:User')
->findOneById($product->getUserId());
//here somehow to concatenate the value from $user to the $products array
}
return $this->json($products, Response::HTTP_OK, [], [
'groups' => ['products']
]);
}
添加樣本輸入和輸出。 – svgrafov
我不認爲' - > findOneById($ id)'(除非您以不同的方式實現它,它與' - > find($ id)''相同)做你認爲它的作用。 – ccKep
不,不是...... – IleNea