Doctrine ORM 问题:[语义错误] 注释不存在,或无法自动加载
Doctrine ORM Issue: [Semantical Error] The annotation does not exist, or could not be auto-loaded
我目前遇到的问题。
Error Encounter: [Semantical Error] The annotation "@Doctrine\ORM\Mapping\Id_users" in property Users\Entity\User::$id_users does not exist, or could not be auto-loaded.
我的实体PHP代码:
<?php
declare(strict_types=1);
namespace Users\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* http://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/basic-mapping.html
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User
{
/**
* @ORM\Id_users
* @ORM\Column(type="integer", name="id_users", nullable=false)
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id_users;
/**
* @ORM\Username
* @ORM\Column(type="varchar", name="username", nullable=false)
*/
protected $username;
/**
* @ORM\Password
* @ORM\Column(type="varchar", name="password", nullable=false)
*/
protected $password;
/**
* @ORM\Email
* @ORM\Column(type="varchar", name="email", nullable=false)
*/
protected $email;
/**
* @ORM\Status
* @ORM\Column(type="integer", name="status", nullable=false)
*/
protected $status;
/**
* @ORM\Date_created
* @ORM\Column(type="datetime", name="date_created", nullable=false)
*/
protected $date_created;
/**
* @ORM\Date_updated
* @ORM\Column(type="datetime", name="date_updated", nullable=true)
*/
protected $date_updated;
/**
* @return int
*/
public function getIdUsers()
{
return $this->id_users;
}
/**
* @param int $id_users
*/
public function setIdUsers($id_users): void
{
$this->id_users = $id_users;
}
/**
* @return mixed
*/
public function getUsername()
{
return $this->username;
}
/**
* @param mixed $username
*/
public function setUsername($username): void
{
$this->username = $username;
}
/**
* @return mixed
*/
public function getPassword()
{
return $this->password;
}
/**
* @param mixed $password
*/
public function setPassword($password): void
{
$this->password = $password;
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* @param mixed $email
*/
public function setEmail($email): void
{
$this->email = $email;
}
/**
* @return mixed
*/
public function getStatus()
{
return $this->status;
}
/**
* @param mixed $status
*/
public function setStatus($status): void
{
$this->status = $status;
}
/**
* @return \DateTime
*/
public function getDateCreated(): \DateTime
{
return $this->date_created;
}
/**
* @param \DateTime $date_created
* @throws \Exception
*/
public function setDateCreated(\DateTime $date_created = null): void
{
if (!$date_created && empty($this->getIdUser())) {
$this->date_created = new \DateTime("now");
} else {
$this->date_created = $date_created;
}
}
/**
* @return \DateTime
*/
public function getDateUpdated(): \DateTime
{
return $this->date_updated;
}
/**
* @param \DateTime $date_updated
* @throws \Exception
*/
public function setDateUpdated(\DateTime $date_updated = null): void
{
if ($date_updated) {
$this->date_updated = new \DateTime("now");
} else {
$this->date_updated = $date_updated;
}
}
}
这是我的配置提供程序片段的片段:
public function getDoctrineEntities() : array
{
return [
'driver' => [
'orm_default' => [
'class' => MappingDriverChain::class,
'drivers' => [
'Users\Entity' => 'user_entity',
],
],
'user_entity' => [
'class' => AnnotationDriver::class,
'cache' => 'array',
'paths' => [__DIR__ . '/Entity'],
]
]
];
}
我已经尝试重命名更新我的标签和变量,但我似乎无法消除这个问题。有没有我错过的配置?我正在使用最新版本的 Zend Expressive。任何建议和意见将不胜感激。
Doctrine中确实没有这样的注解。
您需要从 class 中删除 所有 看起来像 @ORM\{column name}
的注释。
例如属于$id_users
属性的错误信息@ORM\Id_users
中提到了Doctrine。如果您将其删除 - Doctrine 将报告有关下一个 @ORM\Username
等的错误。
@ORM\Id_users
注释无效。 id 字段的正确注释是 @ORM\Id
。它与 属性 的名称无关,但它表明 属性 是主键。
The annotated instance variable will be marked as entity identifier, the primary key in the database. This annotation is a marker only and has no required or optional attributes. For entities that have multiple identifier columns each column has to be marked with @Id.
正如 Flying 所说,您应该删除所有其他属性的 @ORM\{property name}
。可以在 doctrine ocs.
中找到有效注释的完整列表
我目前遇到的问题。
Error Encounter: [Semantical Error] The annotation "@Doctrine\ORM\Mapping\Id_users" in property Users\Entity\User::$id_users does not exist, or could not be auto-loaded.
我的实体PHP代码:
<?php
declare(strict_types=1);
namespace Users\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* http://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/basic-mapping.html
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User
{
/**
* @ORM\Id_users
* @ORM\Column(type="integer", name="id_users", nullable=false)
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id_users;
/**
* @ORM\Username
* @ORM\Column(type="varchar", name="username", nullable=false)
*/
protected $username;
/**
* @ORM\Password
* @ORM\Column(type="varchar", name="password", nullable=false)
*/
protected $password;
/**
* @ORM\Email
* @ORM\Column(type="varchar", name="email", nullable=false)
*/
protected $email;
/**
* @ORM\Status
* @ORM\Column(type="integer", name="status", nullable=false)
*/
protected $status;
/**
* @ORM\Date_created
* @ORM\Column(type="datetime", name="date_created", nullable=false)
*/
protected $date_created;
/**
* @ORM\Date_updated
* @ORM\Column(type="datetime", name="date_updated", nullable=true)
*/
protected $date_updated;
/**
* @return int
*/
public function getIdUsers()
{
return $this->id_users;
}
/**
* @param int $id_users
*/
public function setIdUsers($id_users): void
{
$this->id_users = $id_users;
}
/**
* @return mixed
*/
public function getUsername()
{
return $this->username;
}
/**
* @param mixed $username
*/
public function setUsername($username): void
{
$this->username = $username;
}
/**
* @return mixed
*/
public function getPassword()
{
return $this->password;
}
/**
* @param mixed $password
*/
public function setPassword($password): void
{
$this->password = $password;
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* @param mixed $email
*/
public function setEmail($email): void
{
$this->email = $email;
}
/**
* @return mixed
*/
public function getStatus()
{
return $this->status;
}
/**
* @param mixed $status
*/
public function setStatus($status): void
{
$this->status = $status;
}
/**
* @return \DateTime
*/
public function getDateCreated(): \DateTime
{
return $this->date_created;
}
/**
* @param \DateTime $date_created
* @throws \Exception
*/
public function setDateCreated(\DateTime $date_created = null): void
{
if (!$date_created && empty($this->getIdUser())) {
$this->date_created = new \DateTime("now");
} else {
$this->date_created = $date_created;
}
}
/**
* @return \DateTime
*/
public function getDateUpdated(): \DateTime
{
return $this->date_updated;
}
/**
* @param \DateTime $date_updated
* @throws \Exception
*/
public function setDateUpdated(\DateTime $date_updated = null): void
{
if ($date_updated) {
$this->date_updated = new \DateTime("now");
} else {
$this->date_updated = $date_updated;
}
}
}
这是我的配置提供程序片段的片段:
public function getDoctrineEntities() : array
{
return [
'driver' => [
'orm_default' => [
'class' => MappingDriverChain::class,
'drivers' => [
'Users\Entity' => 'user_entity',
],
],
'user_entity' => [
'class' => AnnotationDriver::class,
'cache' => 'array',
'paths' => [__DIR__ . '/Entity'],
]
]
];
}
我已经尝试重命名更新我的标签和变量,但我似乎无法消除这个问题。有没有我错过的配置?我正在使用最新版本的 Zend Expressive。任何建议和意见将不胜感激。
Doctrine中确实没有这样的注解。
您需要从 class 中删除 所有 看起来像 @ORM\{column name}
的注释。
例如属于$id_users
属性的错误信息@ORM\Id_users
中提到了Doctrine。如果您将其删除 - Doctrine 将报告有关下一个 @ORM\Username
等的错误。
@ORM\Id_users
注释无效。 id 字段的正确注释是 @ORM\Id
。它与 属性 的名称无关,但它表明 属性 是主键。
The annotated instance variable will be marked as entity identifier, the primary key in the database. This annotation is a marker only and has no required or optional attributes. For entities that have multiple identifier columns each column has to be marked with @Id.
正如 Flying 所说,您应该删除所有其他属性的 @ORM\{property name}
。可以在 doctrine ocs.