Symfony2-主义和FOSUserBundle-错误的注释 [英] Symfony2 - Doctrine and FOSUserBundle - wrong annotations

查看:75
本文介绍了Symfony2-主义和FOSUserBundle-错误的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般来说,我是Symfony2的新手.但是,此问题与Doctrine和FOSUserBundle有关.

I am new to Symfony2 in general. This issue relates to Doctrine and FOSUserBundle though.

我有以下基于FOSU​​serBundle和自引用多对多创建的User.php实体.

I have the following User.php Entity created based on FOSUserBundle and a self-referencing many-to many.

<?php

namespace Pan100\MoodLogBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

    /**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;


/**
 * @ManyToMany(targetEntity="User", mappedBy="hasAccessToMe")
 **/
protected $hasAccessTo;

/**
 * @ManyToMany(targetEntity="User", inversedBy="hasAccessTo")
 * @JoinTable(name="access",
 *      joinColumns={@JoinColumn(name="id", referencedColumnName="id")},
 *      inverseJoinColumns={@JoinColumn(name="accessor_id", referencedColumnName="id")}
 *      )
 **/
private $hasAccessToMe;    

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

尝试更新缓存或删除时给我以下错误:

Gives me the following error when attempting to update cache or drop:

[Doctrine\Common\Annotations\AnnotationException]                           
[Semantical Error] The annotation "@ManyToMany" in property Pan100\MoodLog  
Bundle\Entity\User::$hasAccessTo was never imported. Did you maybe forget   
to add a "use" statement for this annotation?

这是怎么了?什么是使用声明"?

What is wrong here? And what is a "use statement"?

推荐答案

您忘记在注释中添加@ORM\前缀:

You forgot to add the @ORM\ prefix in your annotations:

/**
 * @ManyToMany(targetEntity="User", mappedBy="hasAccessToMe")
 **/

应该是

/**
 * @ORM\ManyToMany(targetEntity="User", mappedBy="hasAccessToMe")
 **/

这篇关于Symfony2-主义和FOSUserBundle-错误的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆