【发布时间】:2014-06-26 04:17:25
【问题描述】:
在同一个响应中,我得到一个作为对象的字段和一个作为数组的字段,我该如何纠正这个?
注意我无法控制响应的构建,因为我使用的是 JMSSerializer
代码(编辑 1)
\Entity\Profil.php
class Profil
{
...
/**
* Get actualites
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getActualites()
{
return $this->actualites;
}
...
/**
* Add actualites
*
* @param \Genius\ProfileBundle\Entity\Actualite $actualites
* @return Profil
*/
public function addActualite(\Genius\ProfileBundle\Entity\Actualite $actualites)
{
$this->actualites[] = $actualites;
return $this;
}
...
public function __construct()
{
...
$this->actualites = new \Doctrine\Common\Collections\ArrayCollection();
...
}
【问题讨论】:
-
我需要actualites字段始终是一个数组
-
为了更好地回答您的问题,您必须展示您正在使用的某种代码。
-
你在哪里返回 JsonResponse?
-
@Sehael by
return $this->container->get('genius_profile.actualite.handler')->all($limit, $offset);我基于的教程(参考:welcometothebundle.com/symfony2-rest-api-the-best-2013-way) -
您调用的
all()函数是什么?
标签: php symfony fosrestbundle jmsserializerbundle