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.

j0k
  • 22,600
  • 28
  • 79
  • 90
Richard Knop
  • 81,041
  • 149
  • 392
  • 552
  • 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? – Sam Oct 11 '12 at 18:24
  • I am having the same issue trying to generate the entity classes. Did you get this to work? – atodd Nov 27 '12 at 20:57
  • @atodd Check my answer, I have figured this out. – Richard Knop Nov 28 '12 at 16:22
  • 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? – atodd Nov 30 '12 at 15:41

1 Answers1

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',
            ),
        ),
    ),
),
Richard Knop
  • 81,041
  • 149
  • 392
  • 552