2016-05-22 21 views
2

私はFOSUserBundleを使用しています。私は自分の投稿にコメントを書いたユーザ名を取得する必要があります。FOSUserBundleを使用してqueryBuilder joinでユーザ名を取得

私はポストのコメントを取得し、これは名前を取得しようとしているに参加追加する機能 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; 
    } 

} 

私は「UserBundle」という名前の私のカスタムバンドルにFOSUserBundleを拡張してきたし、それが正常に動作しますしかし、私はこのエンティティとの関係を追加する方法を知らない。

私は結合関係を追加するとき、私は、このエラーが生じています:間違っている

[Semantical Error] line 0, col 164 near 'UserBundle:User': Error: Class 'UserBundle\Entity\User' is not defined.

何?

答えて

2

ドキュメントによれば、ユーザーエンティティの場合はcreate own classにする必要があります。これは、FOSUserによって提供されるものを拡張します。あなたはそれをしていないようです。これはあなたのエラーメッセージが示しているものです。

+0

おかげで、それは動作します!私はそのインストール手順を忘れてしまった。 ; ) – viher

関連する問題