How to configure doctrine extensions in Zend Framework 2?

家住魔仙堡 提交于 2019-12-21 05:15:45

问题


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.


回答1:


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',
            ),
        ),
    ),
),


来源:https://stackoverflow.com/questions/12841102/how-to-configure-doctrine-extensions-in-zend-framework-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!