symfony query-检索一个用户的所有项

xghobddn  于 2021-06-23  发布在  Mysql
关注(0)|答案(2)|浏览(289)

我编写了一个查询来返回特定用户购买的所有卡。我不知道我做错了什么。我在cards表中定义了用户id,并手动添加了一些卡片。
我的服务。。

public function getUserCardAction($userId)
{

    $card = $this->getCardRepository()
        ->createQueryBuilder('c')
        ->select('c')
        ->where('c.userId = :userId')
        ->setParameter('userId', $userId)
        ->getQuery()
        ->getResult();

    return $card;
}

我的控制器。。

public function getUserCard()
{

    $this->get('card.configuration')->getUserCardAction($this->getUser());

    return $this->success();

}
1tuwyuhd

1tuwyuhd1#

我设法找到了解决办法。
我刚刚编辑了我的控制器。

$card = $this->get('card.configuration')->getUserCardAction($this->getUser());

    return $this->success($card);
z4bn682m

z4bn682m2#

你回来了

$this->success();

那是什么功能?
你不应该返回你的查询结果吗?比如:

return $this->get('card.configuration')->getUserCardAction($this->getUser());

相关问题