【发布时间】:2017-10-09 21:29:05
【问题描述】:
有一种方法可以连接 symfony 中 findBy 操作的两个结果吗?如果产品是由用户创建的,我正在尝试将用户对象连接到产品数组。我的代码:
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']
]);
}
【问题讨论】:
-
添加示例输入和输出。
-
我不认为
->findOneById($id)(除非你以不同的方式实现它,它与->find($id)相同)做你认为它做的事情。 -
不,不是……
标签: symfony