Issue I am encountering as of the moment.
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.
My Entity PHP Code:
<?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;
}
}
}
Here is a snippet of my Config Provider Snippet:
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'],
]
]
];
}
I've already tried to rename an update my labels and variables but I can't seem to eliminate this issue. Is there a configuration I missed out? I'm using the latest version of Zend Expressive. Any suggestions and comment will be appreciated.
The @ORM\Id_users
annotation is not valid. The correct annotation for the id field is @ORM\Id
. It is not related to the name of the property, but it is there to indicate the property is the primary key.
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.
As Flying is saying, you should remove @ORM\{property name}
for all other properties. A complete list of valid annotation can be found in the doctrine ocs.