2
我有一个实体与oneToMany的关系,我可以得到相关的项目使用;Doctrine2,PersistentCollection和JMS串行器
$this->getQueuedItems()
这将返回学说\ ORM \ PersistentCollection对象,我再路过这JMS Serializer像这样;
$serializer = $container->get('serializer');
$json = $serializer->serialize($this->getQueuedItems(), 'json');
但是输出使用var_dump()
导致$json
;
串(2) “[]”
哪个是错误的。那里有数据,因为如果我通过foreach()
而不是$this->getQueuedItems()
获得数据。
如何使用JMS串行器将Doctrine \ ORM \ PersistentCollection连载到JSON中?
由于
谢谢@hobnob,我现在一定已经绕过这个方向,但是感谢您的意见。 – 2013-07-23 15:59:54
@JakeN如果可以的话,请发布你如何解决它。在one2many序列化给出的答案是没有帮助的。 – Oshanz 2015-11-02 10:29:39
现在看看我的代码,我甚至不使用'toArray'。你可能想尝试这个包,因为它为你的关系https://github.com/FriendsOfSymfony/FOSRestBundle – 2015-11-02 11:51:40