配置
将扩展添加到你的映射
一些扩展使用它们自己的实体来工作。当你想要使用它们时,你需要在 Doctrine 中注册它们的映射。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# app/config/config.yml
# (or config/packages/doctrine.yaml if you use Flex)
doctrine:
orm:
entity_managers:
default:
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity"
alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_translator:
type: annotation
prefix: Gedmo\Translator\Entity
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translator/Entity"
alias: GedmoTranslator # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_loggable:
type: annotation
prefix: Gedmo\Loggable\Entity
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Loggable/Entity"
alias: GedmoLoggable # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_tree:
type: annotation
prefix: Gedmo\Tree\Entity
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Tree/Entity"
alias: GedmoTree # (optional) it will default to the name set for the mapping
is_bundle: false
注意
如果你正在使用 ORM 配置的简短语法,mappings
键直接位于 orm:
下
注意
如果你正在使用多个实体管理器,请注意为正确的实体管理器注册实体。
注意
MongoDB 的映射是类似的。ODM 文档在每个扩展的 Document
子命名空间中,而不是 Entity
中。
注意
如果你添加了任何这些映射,请务必更新你的模式以添加新表 - 例如,通过生成和执行迁移。
配置实体管理器
你必须为你想要启用扩展的每个实体管理器激活扩展。当使用 ORM 行为时,id 是 DBAL 连接的 id。当使用 mongoDB 时,它是文档管理器的 id。
如果所请求的语言中不存在翻译,此 bundle 需要使用默认的语言环境。如果你没有显式提供它,它将默认为 en
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# app/config/config.yml
# (or config/packages/stof_doctrine_extensions.yaml if you use Flex)
stof_doctrine_extensions:
default_locale: en_US
# Only used if you activated the Uploadable extension
uploadable:
# Default file path: This is one of the three ways you can configure the path for the Uploadable extension
default_file_path: "%kernel.project_dir%/public/uploads"
# Mime type guesser class: Optional. By default, we provide an adapter for the one present in the Mime component of Symfony
mime_type_guesser_class: Stof\DoctrineExtensionsBundle\Uploadable\MimeTypeGuesserAdapter
# Default file info class implementing FileInfoInterface: Optional. By default we provide a class which is prepared to receive an UploadedFile instance.
default_file_info_class: Stof\DoctrineExtensionsBundle\Uploadable\UploadedFileInfo
orm:
default: ~
mongodb:
default: ~
激活你想要的扩展
默认情况下,bundle 不会附加任何监听器。对于你的每个实体管理器,声明你想要启用的扩展
1 2 3 4 5 6 7 8 9 10
# app/config/config.yml
# (or config/packages/stof_doctrine_extensions.yaml if you use Flex)
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
tree: true
timestampable: false # not needed: listeners are not enabled by default
other:
timestampable: true
MongoDB 也可使用相同的方式,在 XML 文件中使用 document-manager
而不是 entity-manager
。
注意
如果你在多个配置文件中配置实体管理器的监听器,则将使用最后一个配置文件。因此,你必须列出所有要分离的监听器。
使用 DoctrineExtensions 库
关于此库的所有解释都可以在官方 DoctrineExtensions 文档中找到。