我使用FOSUserBundle,我需要获取在我的帖子上写评论的用户名。
我使用函数createQuery
来获取帖子评论,并添加此联接以尝试获取名称:
<?php
namespace CommentsBundle\Entity;
use FOS\UserBundle\Entity\User;
/**
* CommentsRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class CommentsRepository extends \Doctrine\ORM\EntityRepository
{
public function getPostComments($planId)
{
$arrPlanComments = array();
$query = $this->getEntityManager()->createQuery(
'SELECT
c.id,
c.fkUser,
c.fkReply,
c.comment,
c.createdAt,
c.likes,
c.unlikes
FROM CommentsBundle:Comments c
INNER JOIN UserBundle:User u
WITH (c.fkUser = u.id)
WHERE
c.fkPlan = :planId
ORDER BY c.createdAt DESC'
)->setParameter('planId', $planId);
try
{
$arrPlanComments = $query->getArrayResult();
}
catch(\Doctrine\ORM\NoResultException $ex)
{
echo $ex->getMessage();
}
return $arrPlanComments;
}
}
我已将FOSUserBundle扩展为名为“UserBundle”的自定义捆绑包,它工作正常,但我不知道如何添加与此实体的关系。
添加连接关系时出现此错误:
[语义错误]第0行,第164行靠近'UserBundle:User':错误:未定义类'UserBundle \ Entity \ User'。
有什么问题?