【问题标题】:FOSRestBundle & Propel & JMSserializerBundle Symfony2FOSRestBundle & Propel & JMSserializerBundle Symfony2
【发布时间】:2023-03-25 07:15:01
【问题描述】:

我正在尝试按照 William Durand 的教程 here 使用 fosrest bundle 和 propel 创建一个 rest api。两天来,我一直在反对连载。我发现一些用户遇到了类似的问题,但没有找到解决方案。

这是我的控制器:

/**
 * @Rest\View
 */
public function allAction(){
    $messages = MessageQuery::create()->find();
    return array('messages' => $messages);
}

我期待消息和 ID 的输出,但是我得到了一个包含有关我的模型的信息的输出:

{ "messages" : { "formatter" : { "as_columns" : [  ],
      "class" : "My\\FooBundle\\Model\\Message",
      "collection_name" : "PropelObjectCollection",
      "current_objects" : [  ],
      "db_name" : "fooDB",
      "has_limit" : false,
      "peer" : "My\\FooBundle\\Model\\MessagePeer",
      "with" : [  ]
    },
  "model" : "My\\FooBundle\\Model\\Message"
} }

我已确保我的 jmsserializer 包具有 propelcollectionhandler.php 补丁。

我的app/config/config.yml有这个

jms_serializer:
    metadata:
        auto_detection: true
        directories:
            Propel:
                namespace_prefix: "My\\FooBundle\\Model\\om"
                path: "@MyFooBundle/Resources/config/serializer"

我在 Github 上的一些示例中看到 namespace_prefix 是空白的,因为他们声称 propel 中的 BaseModel 没有命名空间,但我自动生成的推进基础模型有命名空间,这是新的东西吗1.7?我在有和没有namespace_prefix 的情况下都试过了,我在指定目录中有一个Model.om.BaseTableMessage.yml 文件。

有人遇到过这个问题吗?你是怎么解决的?谢谢!

【问题讨论】:

    标签: php symfony fosrestbundle jmsserializerbundle


    【解决方案1】:

    来自https://groups.google.com/d/msg/symfony2/FqiqJ2dqAM8/8b-9xucG7k4J 的 Quentin Favrie 的解决方案对我有用。

    将此代码添加到My/FooBundle/Resources/config/services.yml

    parameters:
        jms_serializer.propel_collection_handler.class: JMS\Serializer\Handler\PropelCollectionHandler
    
    services:
        jms_serializer.propel_collection_handler:
            class: %jms_serializer.propel_collection_handler.class%
            tags:
                - { name: jms_serializer.subscribing_handler }
    

    【讨论】:

    猜你喜欢
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多