Php 使用FOSUserBundle通过queryBuilder连接获取用户名
我使用FOSUserBundle,我需要获取在我的帖子上写评论的用户名 我使用函数Php 使用FOSUserBundle通过queryBuilder连接获取用户名,php,symfony,doctrine-orm,fosuserbundle,Php,Symfony,Doctrine Orm,Fosuserbundle,我使用FOSUserBundle,我需要获取在我的帖子上写评论的用户名 我使用函数createQuery获取帖子评论,并将此连接添加到尝试获取姓名中: <?php namespace CommentsBundle\Entity; use FOS\UserBundle\Entity\User; /** * CommentsRepository * * This class was generated by the Doctrine ORM. Add your own custom
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;
}
}
根据文档,您必须为用户实体创建一个,它将扩展FOSUser提供的实体。看来你还没那么做。这可能就是您的错误消息所表明的。谢谢,兄弟,它很有效!。我忘记了安装步骤。;)