【发布时间】:2026-01-19 17:20:07
【问题描述】:
在我的 Symfony 2.7 项目中,我使用 StofDoctrineExtension‐Bundle。我已经声明了一些实体。他们使用 Timestampable、Loggable 和 Sluggable Gedmo 行为。我通过阅读 Symfony 官方文档中的 this tutorial 来安装它。当我通过 Sonata Admin 或我自己的用例创建某个实体时,它可以完美运行。
现在我想使用 Gadmo IpTraceable 行为。我通过添加两个属性 ipCreator 和 ipUdater 更改了我的实体声明 ORM YAML 文件:
AppBundle\Entity\Vote:
type: entity
table: te_vote_vot
id:
id:
type: bigint
column: vot_id
generator:
strategy: AUTO
options:
unsigned: true
comment: Identifiant du classement
fields:
created:
type: datetime
nullable: false
column: vot_creation
options:
comment: Creation date
gedmo:
timestampable:
on: create
ipCreator:
type: string
length: 45
nullable: true
column: vot_ip_creator
options:
comment: IP du voteur
gedmo:
ipTraceable:
on: create
ipUpdater:
type: string
length: 45
nullable: true
column: vot_ip_updater
options:
comment: IP du voteur en cas de modification
gedmo:
ipTraceable:
on: update
tracker:
type: guid
nullable: false
column: vot_tracker
options:
comment: Tracker GGUID du voteur
point:
type: smallint
nullable: false
column: vot_point
options:
comment: Nombre de point que rapporte ce vote
[...]
Timestampable 行为被称为 created 属性已很好地初始化,但 ipCreator 不是并保持 null !
为了激活 Timestampable,我在 config.yml 文件中添加了一些行。
stof_doctrine_extensions:
default_locale: fr_FR
orm:
default:
timestampable: true
sluggable: true
loggable: true
我尝试添加iptraceable: true、ipTraceable: true、ip_traceable: true。它不起作用 iptraceable、ipTraceable、ip_traceable 不是配置项。
我查看了DependancyInjection/Configuration.php 源文件。
$node
->useAttributeAsKey('id')
->prototype('array')
->children()
->scalarNode('translatable')->defaultFalse()->end()
->scalarNode('timestampable')->defaultFalse()->end()
->scalarNode('blameable')->defaultFalse()->end()
->scalarNode('sluggable')->defaultFalse()->end()
->scalarNode('tree')->defaultFalse()->end()
->scalarNode('loggable')->defaultFalse()->end()
->scalarNode('sortable')->defaultFalse()->end()
->scalarNode('softdeleteable')->defaultFalse()->end()
->scalarNode('uploadable')->defaultFalse()->end()
->scalarNode('reference_integrity')->defaultFalse()->end()
->end()
->end()
;
这些词都没有激活 IPTraceable 行为。 ipCreator 属性保持为空。我正在搜索一段时间,阅读文档,在网络上搜索。而且我没有找到任何解决方案。
但是in documentation,我读到了这一行:
IpTraceable 还不能作为 Symfony2 的 Bundle 提供,以及 所有其他扩展。
我的英语不流利,但我知道我添加以“手动”激活它,而不是像 Bundle。但我不知道该怎么做。
如何使用这个 IpTracable Doctrine Extensions ?
【问题讨论】:
-
也许您可以尝试使用事件订阅者,就像在他们的文档中一样(即使 ipTraceable 目前不在捆绑包中,他们也有 sf2 项目中的基本实现示例)-link
-
感谢@IlyaYarkovets 提供此链接!我没看到这一段。今晚我将与事件订阅者一起尝试,我会回来转发结果。
-
是的,它适用于事件订阅者。
标签: php symfony doctrine-orm