我在对实体进行 json_encode 时遇到问题。
public function jsonvoteAction($id) {
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('KorumAGBundle:AGVote')->findOneById($id);
$response = new Response(json_encode($entity, 200));
$response->headers->set('Content-Type',' application/json');
return $response;
}
此代码返回我一个用户实体
{"users":{"__isInitialized__":false,"id":null,"nickname":null,"pwd":null,"email":null,"firstname":null,"lastname":null,"poste":null,"addr1":null,"addr2":null,"pc":null,"country":null,"phone":null,"province":null,"acess":null,"site":null,"crew":null,"utilisateur":null}}
当我 var dymp 我的 $entity 时,它会返回我的 AGVote 和 USers 实体。
这是我的 AGVote 实体
<?php
namespace Korum\AGBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Korum\AGBundle\Entity\AGVote
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*/
class AGVote
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
*/
private $id;
/**
* @ORM\Column(type="text")
*/
private $question;
/**
* @ORM\Column(type="smallint")
*/
private $actif;
/**
* @ORM\ManyToOne(targetEntity="\Korum\KBundle\Entity\Users", cascade={"all"})
*/
public $users;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set question
* Nb : Only AG admin can set a question
* @param text $question
*/
public function setQuestion($question)
{
$this->question = $question;
}
/**
* Get question
*
* @return text
*/
public function getquestion()
{
return $this->question;
}
/**
* Set actif
*
* @param smallint $actif
*/
public function setActif($actif)
{
$this->actif = $actif;
}
/**
* Get actif
*
* @return smallint
*/
public function getActif()
{
return $this->actif;
}
/**
* Set Users
*
* @param Korum\KBundle\Entity\Province $Users
*/
public function setUsers(\Korum\KBundle\Entity\Users $users)
{
$this->users = $users;
}
/**
* Get Users
*
* @return Korum\KBundle\Entity\Users
*/
public function getUsers()
{
return $this->users;
}
}
有谁知道发生了什么?
我尝试安装 JSMSerializerBundle,但在 1.1 版本中使用元数据库事件。当我想清除我的缓存时,它失败并出现错误:
请参阅: JMSSerializerBundle 安装:可捕获的致命错误:参数 1 传递给 JMSSerializerBundle\Twig\SerializerExtension::__construct()