[英]FOSRestBundle & Propel & JMSserializerBundle Symfony2
I'm trying to follow William Durand's tutorial here to create a rest api using fosrest bundle and propel. 我试图按照威廉·杜兰德的教程在这里创建使用fosrest捆绑,并推动一个REST API。 I've been beating my head against the serialization for 2 days now. 我已经连续2天对抗序列化了。 I've found some users that ran into a similar problem, but have found no solution. 我发现一些用户遇到了类似的问题,但没有找到解决方案。
Here is my controller: 这是我的控制器:
/**
* @Rest\View
*/
public function allAction(){
$messages = MessageQuery::create()->find();
return array('messages' => $messages);
}
I'm expecting an output of messages and ids, however I get an output with information about my model: 我期待输出消息和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"
} }
I've ensured that my jmsserializer bundle has the propelcollectionhandler.php patch. 我已经确保我的jmsserializer包有propelcollectionhandler.php补丁。
I have this in my app/config/config.yml
我在app/config/config.yml
有这个
jms_serializer:
metadata:
auto_detection: true
directories:
Propel:
namespace_prefix: "My\\FooBundle\\Model\\om"
path: "@MyFooBundle/Resources/config/serializer"
I've seen that the namespace_prefix
is blank on some of the examples on Github, because they claim the BaseModel
in propel has no namespace, but my autogenerated propel base models have a namespace, is this something new in 1.7? 我已经看到在Github上的一些例子中namespace_prefix
是空白的,因为他们声称在推进中的BaseModel
没有命名空间,但是我的自动生成的推进基础模型有一个命名空间,这是1.7中的新内容吗? I have tried it with and without a namespace_prefix
and I do have a Model.om.BaseTableMessage.yml
file in the specified directory. 我在有和没有namespace_prefix
情况下尝试了它,并且我在指定的目录中有一个Model.om.BaseTableMessage.yml
文件。
Has anybody ran into this problem? 有人遇到过这个问题吗? How did you solve it? 你是怎么解决的? Thanks! 谢谢!
Solution from Quentin Favrie from https://groups.google.com/d/msg/symfony2/FqiqJ2dqAM8/8b-9xucG7k4J worked for me. 来自https://groups.google.com/d/msg/symfony2/FqiqJ2dqAM8/8b-9xucG7k4J的 Quentin Favrie的解决方案为我工作。
Add this code to My/FooBundle/Resources/config/services.yml
将此代码添加到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 }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.