我已将这一行添加到我的 composer.json 中:
"gedmo/doctrine-extensions": "dev-master"
这是我模块的module.config.php:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'DoctrineORMMappingDriverAnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'),
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . 'Entity' => __NAMESPACE__ . '_driver'
),
),
),
),
然后我想在我的实体中使用可时间戳的注释,例如:
/**
* @GedmoTimestampable(on="create")
* @ORMColumn(type="datetime",nullable=true)
*/
private $created;
/**
* @GedmoTimestampable(on="update")
* @ORMColumn(type="datetime",nullable=true)
*/
private $updated;
但这行不通。当我使用上述注释保留实体时,创建和更新的列为 NULL。
解决方案是更改我的 module.config.php 更像这样:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'DoctrineORMMappingDriverAnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity'),
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . 'Entity' => __NAMESPACE__ . '_driver'
),
),
),
'eventmanager' => array(
'orm_default' => array(
'subscribers' => array(
'GedmoTimestampableTimestampableListener',
'GedmoSoftDeleteableSoftDeleteableListener',
),
),
),
),