How to configure doctrine extensions in Zend Framework 2?
Asked Answered
D

1

5

I have added this line to my composer.json:

"gedmo/doctrine-extensions": "dev-master"

And this is inside my module's module.config.php:

'doctrine' => array(
    'driver' => array(
        __NAMESPACE__ . '_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'),
        ),
        'orm_default' => array(
            'drivers' => array(
                __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
            ),
        ),
    ),
),

Then I want to use timestampable annotaion in my entities, for example:

/**
 * @Gedmo\Timestampable(on="create")
 * @ORM\Column(type="datetime",nullable=true)
 */
private $created;

/**
 * @Gedmo\Timestampable(on="update")
 * @ORM\Column(type="datetime",nullable=true)
 */
private $updated;

But that doesn't work. When I persist the entity with above annotations, the created and updated columns are NULL.

Darwin answered 11/10, 2012 at 13:48 Comment(4)
Might be too obvious, but you also adde Gedmo namespace to be loaded? In both, application.config.php and the usestatements inside your entity-class?Presently
I am having the same issue trying to generate the entity classes. Did you get this to work?Trumpet
@Trumpet Check my answer, I have figured this out.Darwin
Thanks Richard, I actually have the subscribers working but I can't get the annotations into my entity classes from yaml files using the doctrine orm:generate-entities tool. Can you shed some light on how you go the annotations working?Trumpet
D
12

The solution was to change my module.config.php to be more like this:

'doctrine' => array(
    'driver' => array(
        __NAMESPACE__ . '_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'),
        ),
        'orm_default' => array(
            'drivers' => array(
                __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
            ),
        ),
    ),
    'eventmanager' => array(
        'orm_default' => array(
            'subscribers' => array(
                'Gedmo\Timestampable\TimestampableListener',
                'Gedmo\SoftDeleteable\SoftDeleteableListener',
            ),
        ),
    ),
),
Darwin answered 28/11, 2012 at 16:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.