Php 如何在Symfony 2.7项目中激活可跟踪的Gedmo Ip_?

Php 如何在Symfony 2.7项目中激活可跟踪的Gedmo Ip_?,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,在我的Symfony 2.7项目中,我使用。我已经申报了一些实体。它们使用可时间戳、可日志和可段塞的Gedmo行为。我通过阅读Symfony官方文档安装了它。当我通过Sonata Admin或我自己的用例创建某个实体时,它可以完美地工作 现在我想使用Gadmo IpTraceable行为。我通过添加两个属性ipCreator和ipUdater更改了实体声明ORM YAML文件: AppBundle\Entity\Vote: type: entity table: te_vote_vot

在我的Symfony 2.7项目中,我使用。我已经申报了一些实体。它们使用可时间戳、可日志和可段塞的Gedmo行为。我通过阅读Symfony官方文档安装了它。当我通过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
  [...]
时间标记行为已被调用
已创建
属性初始化良好,但
ipCreator
未被调用且保持为
null

为了激活timestable,我在
config.yml
文件中添加了一些行

stof_doctrine_extensions:
    default_locale: fr_FR
    orm:
        default:
            timestampable: true
            sluggable: true
            loggable: true
我试图添加
iptraceable:true
iptraceable:true
ip\u traceable:true
。它不起作用,可iptraceable、可iptraceable、可ip_追踪都不是配置术语

我查看了源文件

$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()
;
这些词中没有一个能激活可追踪的行为。ipCreator属性保持为null。我在搜索一段时间,阅读文档,在网上搜索。我没有找到任何解决办法

但是,我读到这一行:

IpTraceable尚未作为Symfony2的捆绑包提供,以及 所有其他扩展

我的英语不是很流利,但我知道我是“手动”添加来激活它的,不像一个捆绑包。但我不知道怎么做

如何使用此IpTracable条令扩展?

方法1:使用事件订阅服务器 正如@Ilya所建议的,我试过使用事件订阅服务器,如中所示

但是很难配置服务,因为我使用的是yml

下面是该文件的yaml版本:

方法2:等待合并拉取请求#233 自2014年3月以来,增加了对IpTraceable Gedmo扩展的支持。您可以等待拉取请求与主请求合并@不幸的是,斯托夫似乎没有时间做这个项目。我不知道什么时候能完成

方法3:使用AlterPHP fork! 您可以从composer.json中删除Stof/StofDoctrineExtensions并使用

别忘了调用iptraceable侦听器分支

您必须通过编辑app/config/config.yml文件来激活ip_可跟踪订户

stof_doctrine_extensions:
    orm:
        default:
            ip_traceable: true
例如,下面是我的config.yml文件:

stof_doctrine_extensions:
    default_locale: fr_FR
    orm:
        default:
            timestampable: true
            sluggable: true
            loggable: true
            ip_traceable: true
我尝试了方法1和2,两种方法都非常有效。(当然不是在一起)


所以你自己选吧;)

也许您可以尝试使用事件订阅者,就像在他们的文档中一样(即使目前还没有捆绑包中的ipTraceable,他们也有sf2项目中的基本实现示例)-感谢@IlyaYarkovets的链接!我没有看到这一段。今晚我将尝试使用事件订阅服务器,然后返回转发结果。是的,它与事件订阅服务器一起工作。在使用SF3的方法1中,您需要在@like:
“@gedmo\u doctrine\u extensions.listener.ip\u traceable”之前添加简单的引号。
stof_doctrine_extensions:
    default_locale: fr_FR
    orm:
        default:
            timestampable: true
            sluggable: true
            loggable: true
            ip_traceable: true