@Doctrine\ORM\映射\ "Annotation was never imported"



所以我是Doctrine和PHP的新手,我有一个小问题不知道如何解决。。。我需要创建一个PHP应用程序(使用Doctrine(,并与我的前任使用DoctrineORM的DB进行通信;所以我试着用他的一个文件作为模板来制作我的应用程序,但它似乎不起作用。。。

首先,他的文件被用作模板:

<?php
namespace AppEntity;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineCommonCollectionsCollection;
use DoctrineORMMapping as ORM;
use SymfonyComponentSecurityCoreUserUserInterface;
use SymfonyComponentValidatorConstraints as Assert;
use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity;
use SymfonyComponentSerializerAnnotationGroups;
/**
* @ORMEntity(repositoryClass="AppRepositoryUserRepository")
* @UniqueEntity("email")
*/
class User implements UserInterface
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
* @Groups({"campaign_get", "user_logged"})
*/
private $id;
/**
* @ORMColumn(type="string", length=180, unique=true)
* @AssertNotBlank
* @AssertEmail
* @Groups({"campaign_get", "user_logged"})
*/
private $email;

/**
* @var string The hashed password
* @ORMColumn(type="string")
* @AssertNotBlank
*  @AssertRegex(
*  pattern="/^(?=.{8,}$)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$/",
*  message="Votre mot de passe doit contenir au moins 1 chiffre, 1 majuscule, 1 minuscule et avoir une longueur d'au moins 8 caractères."
* )
*/
private $password;
/**
* @ORMColumn(type="string", length=100)
* @AssertNotBlank
* @Groups("campaign_get")
*/
private $firstname;
/**
* @ORMColumn(type="string", length=100)
* @AssertNotBlank
* @Groups("campaign_get")
*/
private $lastname;
/**
* @ORMColumn(type="boolean")
*/
private $status;
/**
* @ORMColumn(type="string", length=100, nullable=true)
*/
private $idInstagram;
/**
* @ORMColumn(type="string", length=100, nullable=true)
*/
private $idFacebook;
/**
* @ORMColumn(type="string", length=100, nullable=true)
*/
private $idYoutube;
/**
* @ORMColumn(type="string", length=100, nullable=true)
*/
private $idSnapchat;
/**
* @ORMColumn(type="string", length=100, nullable=true)
*/
private $idTiktok;
/**
* @ORMColumn(type="datetime")
*/
private $createdAt;
/**
* @ORMColumn(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORMManyToMany(targetEntity="AppEntityRole")
* @Groups("campaign_get")
*/
private $userRoles;
/**
* @ORMManyToMany(targetEntity="AppEntityArticle", mappedBy="users")
*/
private $articles;
/**
* @ORMColumn(type="string", length=100, nullable=true)
*/
private $companyName;
/**
* @ORMManyToMany(targetEntity="AppEntityCampaign", mappedBy="users")
*/
private $campaigns;
/**
* @ORMColumn(type="string", length=255, nullable=true)
*/
private $resetToken;
public function __construct()
{
$this->userRoles = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->status = 1;
$this->createdAt = new DateTime();
$this->campaigns = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->userRoles;
$userRoles = [];
foreach ($roles as $role) {
$userRoles[] = $role->getName();
}
return $userRoles;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getStatus(): ?bool
{
return $this->status;
}
public function setStatus(bool $status): self
{
$this->status = $status;
return $this;
}
public function getIdInstagram(): ?string
{
return $this->idInstagram;
}
public function setIdInstagram(?string $idInstagram): self
{
$this->idInstagram = $idInstagram;
return $this;
}
public function getIdFacebook(): ?string
{
return $this->idFacebook;
}
public function setIdFacebook(?string $idFacebook): self
{
$this->idFacebook = $idFacebook;
return $this;
}
public function getIdYoutube(): ?string
{
return $this->idYoutube;
}
public function setIdYoutube(?string $idYoutube): self
{
$this->idYoutube = $idYoutube;
return $this;
}
public function getIdSnapchat(): ?string
{
return $this->idSnapchat;
}
public function setIdSnapchat(?string $idSnapchat): self
{
$this->idSnapchat = $idSnapchat;
return $this;
}
public function getCreatedAt(): ?DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getIdTiktok(): ?string
{
return $this->idTiktok;
}
public function setIdTiktok(?string $idTiktok): self
{
$this->idTiktok = $idTiktok;
return $this;
}
/**
* @return Collection|Role[]
*/
public function getUserRoles(): Collection
{
return $this->userRoles;
}
public function addUserRole(Role $userRole): self
{
if (!$this->userRoles->contains($userRole)) {
$this->userRoles[] = $userRole;
}
return $this;
}
public function removeUserRole(Role $userRole): self
{
if ($this->userRoles->contains($userRole)) {
$this->userRoles->removeElement($userRole);
}
return $this;
}
/**
* @return Collection|Article[]
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): self
{
if (!$this->articles->contains($article)) {
$this->articles[] = $article;
$article->addUser($this);
}
return $this;
}
public function removeArticle(Article $article): self
{
if ($this->articles->contains($article)) {
$this->articles->removeElement($article);
$article->removeUser($this);
}
return $this;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(?string $companyName): self
{
$this->companyName = $companyName;
return $this;
}
/**
* @return Collection|Campaign[]
*/
public function getCampaigns(): Collection
{
return $this->campaigns;
}
public function addCampaign(Campaign $campaign): self
{
if (!$this->campaigns->contains($campaign)) {
$this->campaigns[] = $campaign;
$campaign->addUser($this);
}
return $this;
}
public function removeCampaign(Campaign $campaign): self
{
if ($this->campaigns->contains($campaign)) {
$this->campaigns->removeElement($campaign);
$campaign->removeUser($this);
}
return $this;
}
public function getResetToken(): ?string
{
return $this->resetToken;
}
public function setResetToken(?string $resetToken): self
{
$this->resetToken = $resetToken;
return $this;
}
}

然后,我使用相同的哲学:

<?php
namespace AppEntity;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineCommonCollectionsCollection;
use DoctrineORMMapping as ORM;
use SymfonyComponentSecurityCoreUserUserInterface;
use SymfonyComponentValidatorConstraints as Assert;
use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity;
use SymfonyComponentSerializerAnnotationGroups;
/**
* @ORMEntity(repositoryClass="AppRepositoryAgencyRepository")
*/
class Agency
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMnameAgency()
* @ORMColumn(type"string")
*/
private $nameAgency;
/**
* @ORMnameContact
* @ORMColumn(type="string")
* @AssertNotBlank
*/
private $nameContact;
}

然后我试着运行这个:

php bin/console doctrine:migrations:diff

进入终端来更新DB,它与以前的文件(用户类(一起工作很好,但我的文件(代理类(抛出了一个错误:

[Semantical Error] The annotation "@DoctrineORMMappingnameAgency" in property AppEntityAgency::$nameAgency was never imported. Did you maybe forget to add    
a "use" statement for this annotation?  

起初我认为这是导入的问题,所以我进行了与User Class中完全相同的导入,但错误仍然存在。

在谷歌上搜索这个错误,我发现了一个github问题,并将其作为修复方案;但它似乎对我不起作用…

我应该怎么做才能解决这个问题?

您正在使用

@ORMnameAgency()

显然这个注释不存在,为什么你有它?

删除@ORMnameAgency()@ORMnameContact,这没有任何意义。

说明:你所说的@ORMnameAgency()实际上是指DoctrineORMMappingnameAgency,这个注释在教义中自然不存在。

相关内容

  • 没有找到相关文章

最新更新