Though the OP's answer is correct, it's not complete. Below what I've done and why.
Create own User Entity. AbstractEntity is one used for all my Entities, contains just the ID property, getters/setter and some global functionality for Entity debugging.
User.php
use Doctrine\ORM\Mapping as ORM;
use Keet\Mvc\Entity\AbstractEntity;
use ZfcUser\Entity\UserInterface;
/**
* Entity Class representing a post of our User module.
*
* @ORM\Entity
* @ORM\Table(name="users")
* @ORM\Entity(repositoryClass="Keet\User\Repository\UserRepository")
* @ORM\HasLifecycleCallbacks
*/
class User extends AbstractEntity implements UserInterface
{
/**
* @var string
* @ORM\Column(name="username", type="string", length=255, unique=true, nullable=false)
*/
protected $username;
/**
* @var string
* @ORM\Column(name="email", type="string", length=255, unique=true, nullable=false)
*/
protected $email;
/**
* @var string
* @ORM\Column(name="display_name", type="string", length=255, nullable=false)
*/
protected $displayName;
/**
* @var string
* @ORM\Column(name="`password`", type="string", length=255, nullable=false)
*/
protected $password;
/**
* @var int
* @ORM\Column(name="state", type="integer", length=3, nullable=false)
*/
protected $state = 1;
// Getters/Setters
}
zfcuser.config.php
Contains the same config as OP's answer:
'zfcuser' => [
//Some other config
'userEntityClass' => User::class,
'EnableDefaultEntities' => false,
],
module.config.php
IMPORTANT: Overwrite the default doctrine entity config of zfcuser!
'doctrine' => [
'orm_autoload_annotations' => true,
'driver' => [
__NAMESPACE__ . '_driver' => [
'class' => 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver',
'cache' => 'array',
'paths' => [
__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src'
. DIRECTORY_SEPARATOR . 'Entity',
]
],
'orm_default' => [
'drivers' => [
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver',
'ZfcUser\Entity' => __NAMESPACE__ . '_driver'
],
],
'zfcuser_entity' => [ // Section overwrites the default config for location of Annotation. Original found
// in vendor ZfcUserDoctrineModule /config/xml/zfcuser/ZfcUser.Entity.User.dcm.xml
'class' => 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver',
'paths' =>
__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src'
. DIRECTORY_SEPARATOR . 'Entity',
],
],
],
In the above you'd normally just have the 'driver'
and 'orm_default'
configs. ZfcUser module contains a the 'zfcuser_entity'
config, but points it to the driver within it's own module. To not have a floating reference to a different driver, overwrite it and point it towards your own defined driver, defined by __NAMESPACE__ . '_driver'
. Also, in my example I use the AnnotationDriver
for reading annotation, whereas the ZfcUser module uses the XmlDriver
. ZfcUser module config below
This is the original config, overwritten in the above example
'zfcuser_entity' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\XmlDriver',
'paths' => __DIR__ . '/xml/zfcuser'
),
This config allows you to fully use your own Entity, but still use the ZfcUser module.
In my case I can use my own AbstractActionController
with my self-written CRUD actions, which expect a child of AbstractEntity
. This saves a lot of writing/thinking ;)