我正在尝试按照 William Durand 的教程在这里使用 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"
我已经看到namespace_prefix
Github 上的一些示例中的空白,因为他们声称BaseModel
in propel 没有命名空间,但我自动生成的推进基础模型有一个命名空间,这是 1.7 中的新内容吗?我已经尝试过使用和不使用 a namespace_prefix
,并且在指定目录中确实有一个Model.om.BaseTableMessage.yml
文件。
有人遇到过这个问题吗?你是怎么解决的?谢谢!