Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure doctrine extensions in Zend Framework 2?

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.

like image 513
Richard Knop Avatar asked Oct 11 '12 13:10

Richard Knop


1 Answers

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',
            ),
        ),
    ),
),
like image 182
Richard Knop Avatar answered Nov 03 '22 00:11

Richard Knop