JMSSerializerBundle 混合自动检测和显式目录? [英] JMSSerializerBundle mixing auto detection and explicit directories?

查看:24
本文介绍了JMSSerializerBundle 混合自动检测和显式目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以对某些包使用 auto_detection,同时通过为它们指定 directories 来覆盖第三方模型的位置?

Is it possible to use auto_detection for some bundles, while overriding the location of third-party models by specifying directories for them?

过去几天我一直在玩 JMSSerializerBundle 试图理解它并获得它处理个人项目,并且看起来没有任何方法可以使用 auto_detection 以及为第三方元数据指定 directories.

I've been playing with the JMSSerializerBundle the past couple of days trying to understand it and get it to work with a personal project, and it doesn't look like there is any way to use auto_detection as well as specify directories for third-party metadata.

如果我编写我的 FOSUserBundle Model.User.yml 序列化数据,例如:

If I write my FOSUserBundle Model.User.yml serialization data, e.g.:

FOS\UserBundle\Model\User:
    access_type: property
    exclusion_policy: ALL
    xml_root_name: user
    properties:
        username:
            type:     string
            expose:   true

并将其放在指定的目录中,同时将 auto_detection 设置为 true,如下所示:

And place it in the directory specified, while auto_detection is set to true, like so:

jms_serializer:
  metadata:
    debug: true
    file_cache:
      dir: "%kernel.cache_dir%/serializer"
    auto_detection: true
    directories:
      FOSUserBundle:
        namespace_prefix: FOS\UserBundle
        path: "@MyBundle/config/serializer/fosuser"

未选取序列化元数据.

但是,如果我将相同的元数据文件放在 FOS/UserBundle/Resources/config/serializer(在供应商包中)并将配置更改为:

However, if I place the same metadata file under FOS/UserBundle/Resources/config/serializer (in the vendor bundle) and change the configuration to:

jms_serializer:
  metadata:
    debug: true
    file_cache:
      dir: "%kernel.cache_dir%/serializer"
    auto_detection: true
    #directories:
    #  FOSUserBundle:
    #    namespace_prefix: FOS\UserBundle
    #    path: "@MyBundle/config/serializer/fosuser"

读取并正确应用序列化元数据.

The serialization metadata is read and properly applied.

推荐答案

目录路径有误,应该是:

There was a typo in the directory path, it should have read:

jms_serializer:
  metadata:
    debug: true
    file_cache:
      dir: "%kernel.cache_dir%/serializer"
    auto_detection: true
    directories:
      FOSUserBundle:
        namespace_prefix: FOS\UserBundle
        path: "@MyBundle/Resources/config/serializer/fosuser"

让我深入研究 FileLocator 以了解文件未加载的原因.

Took me digging into the FileLocator to understand why the file was not being loaded.

这篇关于JMSSerializerBundle 混合自动检测和显式目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆