duandi8544 2014-04-06 13:19
浏览 37
已采纳

ManyToMany与FOSUserBundle的学说关系

I would like to make a relationship ManyToMany with two entity:

  • User (used with FOSUserBundle)
  • Categorie

For the moment, I'm doing this in "MyNamespace/Userbundle/Entity/User.php" :

/**
 * @ORM\ManyToMany(targetEntity="\MyNamespace\WebsiteBundle\Entity\Categorie", inversedBy="users")
 * @ORM\JoinTable(name="user_has_categories")
 */
private $categories;

public function __construct()
{
    parent::__construct();
    $this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}

And this in "MyNameSpace/WebsiteBundle/Entity/Categorie.php" :

/**
 * @ORM\ManyToMany(targetEntity="\MyNameSpace\UserBundle\Entity\User", mappedBy="categories")
 */
 private $users;

 public function __construct()
 {
   $this->users = new \Doctrine\Common\Collections\ArrayCollection();
 }

When I run the doctrine command for create the table with the reationship, everything is OK.

But when I do a var_dump($this->getUser()); in my default controller (for exemple), I have an infinite loop that crashes my browser. This effect no longer appears when I delete the relationship in my User entity ...

That would have an idea where this problem may be?

I turn with php 5.4.9 on ubuntu

Thank's :)

  • 写回答

1条回答 默认 最新

  • dsa88885555 2014-04-06 13:31
    关注

    Use

    Doctrine\Common\Util\Debug::dump()

    Instead of var_dump

    -Updated-

    Why Debug::dump() works but var_dump doesn't:

    Doctrine\Common\Util\Debug::dump() accept second parameter maxDepth with default value = 2 to limit the nested reference to two level. You can pass this value as you like.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大