I ran into a symfony circular link issue that I suspect caused by a serializer, but I haven't found the answers yet. Here are the entities I created, route and controller. Any suggestions in this regard would be greatly appreciated.
User.php
class User
{
private $id;
private $dietas;
public function __construct()
{
$this->dietas = new ArrayCollection();
}
}
Diet.php
class Dieta
{
private $id;
private $user;
public function __construct()
{
$this->user = new ArrayCollection();
}
}
Route
/**
* @Route("dietas/list/user/{id}", name="userDietas")
*/
DietaController.php Method
public function userListAction($id)
{
$encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new Serializer($normalizers, $encoders);
$user = $this->getDoctrine()
->getRepository('AppBundle:User')->find($id);
$dietaDatas = $user->getDietas();
if(!$dietaDatas) {
throw $this->createNotFoundException(
'There is no data...'
);
}
$jsonContent = $serializer->serialize($dietaDatas, 'json');
return new Response($jsonContent);
}
source
share