【发布时间】:2018-05-30 12:46:36
【问题描述】:
我写了一个查询来返回特定用户购买的所有卡。我不知道我做错了什么。我在卡片表中定义了 user_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();
}
【问题讨论】:
-
你得到了什么错误?
-
它返回 TRUE 但没有数据。我在 db 中输入了 user_id 1 的卡片。
-
向我们展示你的实体类
-
/** * @ORM\Column(name="user_id", type="integer", nullable=true) */ private $userId;
标签: php mysql function symfony