【问题标题】:How can I log username and email address with StofDoctrineBundle?如何使用 StofDoctrineBundle 记录用户名和电子邮件地址?
【发布时间】:2013-12-16 11:28:40
【问题描述】:

我正在使用 Symfony2 运行 Symfony2 应用程序,并且我正在使用 FOSUserBundle 来管理我的用户。

现在我实现了StofDoctrineExtensionsBundle 以使用可记录扩展。不幸的是,我无法记录usernameemail。如果我尝试通过 YML 激活日志记录:

Acme\MyBundle\Entity\User:
  type: entity
  gedmo:
    loggable: true
  fields:
    id:
      ...
    username:
      type: string
      gedmo:
        - versioned
    email:
      type: string
      gedmo:
        - versioned

我得到一个

字段或鉴别器列映射中实体上列“用户名”的重复定义。

所以我尝试激活登录注释(请注意,我通过 YML 定义了所有其他实体):

use FOS\UserBundle\Model\User as BaseUser;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @Gedmo\Loggable
 */
class User extends BaseUser {
    ...
    /**
     * @var string
     * @Gedmo\Versioned
     */
    protected $username;

    /**
     * @var string
     * @Gedmo\Versioned
     */
    protected $email;

但是:什么也没发生。我的User 的所有其他属性都已记录,但usernameemail 没有记录。

为了激活这两个属性的日志记录,我必须进行哪些更改?或者这是我无法影响的 FOSUserBundle 和 StofDoctrineExtensionsBundle 之间的相互依赖关系?

【问题讨论】:

  • 您有重复的字段username。您可能需要将email 放在那里。
  • 啊,不抱歉。那只是在这个片段中。我在我的代码中得到了正确的。我更新了,谢谢你的信息。

标签: symfony logging bundle yaml add-on


【解决方案1】:

你添加了这个配置吗?:

   //app/config/config.yml
    orm:
      auto_generate_proxy_classes: "%kernel.debug%"
      auto_mapping: true
      mappings:
       translatable:
          type: annotation
          alias: Gedmo
          prefix: Gedmo\Translatable\Entity
          dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
       loggable:
          type: annotation
          alias: Gedmo
          prefix: Gedmo\Loggable\Entity
          dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
       tree:
          type: annotation
          alias: Gedmo
          prefix: Gedmo\Tree\Entity
          dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
       sluggable:
          type: annotation
          alias: Gedmo
          prefix: Gedmo\Sluggable\Entity
          dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"

【讨论】:

  • 是的,正如我的问题中所写,可记录的作品,但不适用于用户名和电子邮件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-28
  • 1970-01-01
  • 1970-01-01
  • 2014-10-08
  • 2020-03-11
  • 1970-01-01
相关资源
最近更新 更多