Получатель Symfony 2 возвращает ошибку: {& quot; __ инициализатор __ & quot;: {}, & quot; __ cloner __ & quot;: {}, & quot; __ isInitialized __ & quot;: false}

У меня проблема с геттером, созданным Symfony 2 при попытке создать JSON. Получатель — getNcomptador (), который возвращает вид ошибки.

Вызванная функция для создания JSON:

public function llistatLecturesAction($db){

$sessio = $this->getRequest()->getSession()->get('aquagest');

$arrayAuxiliar = array();

$lecturesRepository = $this->getDoctrine()
->getRepository('AquagestLecturesBundle:Lectura', 'aquagest_'.$db);
$lectures = $lecturesRepository->findBy(array(),array('id'=>'ASC'));

$elmarray = array();

foreach ($lectures as $lectura) {
$aux['id'] = $lectura->getId();
$aux['any'] = $lectura->getLecany();
$aux['trimestre'] = $lectura->getTrimestre();
$aux['lectura'] = $lectura->getLectura();
$aux['nComptador'] = $lectura->getNcomptador();
//if($lectura->getId() == 1) $prova = $lectura->getNcomptador();

array_push($elmarray, $aux);
$i++;
}

return new JsonResponse($elmarray);

}

Lectura Entity:

<?php

namespace Aquagest\LecturesBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Lectura
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Aquagest\LecturesBundle\Repository\LecturaRepository")
*/
class Lectura
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var \DateTime
*
* @ORM\Column(name="data", type="datetime")
*/
private $data;

/**
* @var integer
*
* @ORM\Column(name="trimestre", type="integer")
*/
private $trimestre;

/**
* @var integer
*
* @ORM\Column(name="lecany", type="integer")
*/
private $lecany;

/**
* @var float
*
* @ORM\Column(name="lectura", type="float")
*/
private $lectura;

/**
* @ORM\ManyToOne(targetEntity="Aquagest\SubministramentsBundle\Entity\ComptadorSubministrament", inversedBy="lectures")
* @ORM\JoinColumn(name="lectura_ncomptador", referencedColumnName="id", onDelete="CASCADE")
*/
protected $ncomptador;

/**
* @var string
*
* @ORM\Column(name="fotografia", type="string", length=255)
*/
private $fotografia = "";

/**
* @var boolean
*
* @ORM\Column(name="incidencia", type="boolean")
*/
private $incidencia;

/**
* @var boolean
*
* @ORM\Column(name="estacional", type="boolean")
*/
private $estacional;

/**
* @var boolean
*
* @ORM\Column(name="anomalia", type="boolean")
*/
private $anomalia;

/**
* @var boolean
*
* @ORM\Column(name="panterior", type="boolean")
*/
private $panterior;

/**
* @var string
*
* @ORM\Column(name="motiuIncidencia", type="string", length=255)
*/
private $motiuIncidencia = "";

/**
* @var string
*
* @ORM\Column(name="tipus", type="string", length=255)
*/
private $tipus;

/**
* @var float
*
* @ORM\Column(name="consum", type="float")
*/
private $consum;

/**
* @var boolean
*
* @ORM\Column(name="canviComptador", type="boolean", options={"default"=false})
*/
private $canviComptador = false;

/**
* @var boolean
*
* @ORM\Column(name="voltaComptador", type="boolean", options={"default"=false})
*/
private $voltaComptador = false;

/**
* @var float
*
* @ORM\Column(name="numDigits", type="float", nullable=true, options={"default"=null})
*/
private $numDigits = null;

/**
* @var float
*
* @ORM\Column(name="lecturaInicial", type="float", nullable=true, options={"default"=null})
*/
private $lecturaInicial = null;

/**
* @var boolean
*
* @ORM\Column(name="regularitzacio", type="boolean", options={"default"=false})
*/
private $regularitzacio = false;

/**
* @ORM\OneToMany(targetEntity="Aquagest\AlertesabastamentBundle\Entity\RegistreAlertaAbastament", mappedBy="lecturaSubministrament")
*/
protected $registreAlertes;

/**
* @ORM\OneToOne(targetEntity="Aquagest\ComptabilitatBundle\Entity\FacturaLectura", inversedBy="lectura")
* @ORM\JoinColumn(name="lectura_factura", referencedColumnName="id", onDelete="CASCADE")
*/
protected $factura;/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set data
*
* @param \DateTime $data
* @return Lectura
*/
public function setData($data)
{
$this->data = $data;

return $this;
}

/**
* Get data
*
* @return \DateTime
*/
public function getData()
{
return $this->data;
}

/**
* Set trimestre
*
* @param integer $trimestre
* @return Lectura
*/
public function setTrimestre($trimestre)
{
$this->trimestre = $trimestre;

return $this;
}

/**
* Get trimestre
*
* @return integer
*/
public function getTrimestre()
{
return $this->trimestre;
}

/**
* Set lecany
*
* @param integer $lecany
* @return Lectura
*/
public function setLecany($lecany)
{
$this->lecany = $lecany;

return $this;
}

/**
* Get lecany
*
* @return integer
*/
public function getLecany()
{
return $this->lecany;
}

/**
* Set lectura
*
* @param float $lectura
* @return Lectura
*/
public function setLectura($lectura)
{
$this->lectura = $lectura;

return $this;
}

/**
* Get lectura
*
* @return float
*/
public function getLectura()
{
return $this->lectura;
}

/**
* Set ncomptador
*
* @param \Aquagest\SubministramentsBundle\Entity\ComptadorSubministrament $ncomptador
* @return Lectura
*/
public function setNcomptador(\Aquagest\SubministramentsBundle\Entity\ComptadorSubministrament $ncomptador = null)
{
$this->ncomptador = $ncomptador;

return $this;
}

/**
* Get ncomptador
*
* @return \Aquagest\SubministramentsBundle\Entity\ComptadorSubministrament
*/
public function getNcomptador()
{
return $this->ncomptador;
}

/**
* Set fotografia
*
* @param string $fotografia
* @return Lectura
*/
public function setFotografia($fotografia)
{
$this->fotografia = $fotografia;

return $this;
}

/**
* Get fotografia
*
* @return string
*/
public function getFotografia()
{
return $this->fotografia;
}

/**
* Set incidencia
*
* @param boolean $incidencia
* @return Lectura
*/
public function setIncidencia($incidencia)
{
$this->incidencia = $incidencia;

return $this;
}

/**
* Get incidencia
*
* @return boolean
*/
public function getIncidencia()
{
return $this->incidencia;
}

/**
* Set estacional
*
* @param boolean $estacional
* @return Lectura
*/
public function setEstacional($estacional)
{
$this->estacional = $estacional;

return $this;
}

/**
* Get estacional
*
* @return boolean
*/
public function getEstacional()
{
return $this->estacional;
}

/**
* Set anomalia
*
* @param boolean $anomalia
* @return Lectura
*/
public function setAnomalia($anomalia)
{
$this->anomalia = $anomalia;

return $this;
}

/**
* Get anomalia
*
* @return boolean
*/
public function getAnomalia()
{
return $this->anomalia;
}

/**
* Set panterior
*
* @param boolean $panterior
* @return Lectura
*/
public function setPanterior($panterior)
{
$this->panterior = $panterior;

return $this;
}

/**
* Get panterior
*
* @return boolean
*/
public function getPanterior()
{
return $this->panterior;
}

/**
* Set motiuIncidencia
*
* @param string $motiuIncidencia
* @return Lectura
*/
public function setMotiuIncidencia($motiuIncidencia)
{
$this->motiuIncidencia = $motiuIncidencia;

return $this;
}

/**
* Get motiuIncidencia
*
* @return string
*/
public function getMotiuIncidencia()
{
return $this->motiuIncidencia;
}

/**
* Set tipus
*
* @param string $tipus
* @return Lectura
*/
public function setTipus($tipus)
{
$this->tipus = $tipus;

return $this;
}

/**
* Get tipus
*
* @return string
*/
public function getTipus()
{
return $this->tipus;
}

/**
* Set consum
*
* @param float $consum
* @return Lectura
*/
public function setConsum($consum)
{
$this->consum = $consum;

return $this;
}

/**
* Get consum
*
* @return float
*/
public function getConsum()
{
return $this->consum;
}

/**
* Funció que crea la carpeta de la lectura
* @return [type] [description]
*/
public function createFolder($plataforma){
try{
umask(0000);
mkdir("./uploads/".$plataforma."/lectures/lectura_".$this->id);
return true;
}catch(Exception $e){
return false;
}
}

/**
* Funció que elimina la carpeta de la lectura
* @return [type] [description]
*/
public function removeFolder($plataforma){
try{
umask(0000);
$dir = "./uploads/".$plataforma."/lectures/lectura_".$this->id;
shell_exec("rm -Rf ".$dir);
return true;
}catch(Exception $e){
return false;
}
}

/**
* Set canviComptador
*
* @param boolean $canviComptador
* @return Lectura
*/
public function setCanviComptador($canviComptador)
{
$this->canviComptador = $canviComptador;

return $this;
}

/**
* Get canviComptador
*
* @return boolean
*/
public function getCanviComptador()
{
return $this->canviComptador;
}

/**
* Set voltaComptador
*
* @param boolean $voltaComptador
* @return Lectura
*/
public function setVoltaComptador($voltaComptador)
{
$this->voltaComptador = $voltaComptador;

return $this;
}

/**
* Get voltaComptador
*
* @return boolean
*/
public function getVoltaComptador()
{
return $this->voltaComptador;
}

/**
* Set numDigits
*
* @param float $numDigits
* @return Lectura
*/
public function setNumDigits($numDigits)
{
$this->numDigits = $numDigits;

return $this;
}

/**
* Get numDigits
*
* @return float
*/
public function getNumDigits()
{
return $this->numDigits;
}

/**
* Set lecturaInicial
*
* @param float $lecturaInicial
* @return Lectura
*/
public function setLecturaInicial($lecturaInicial)
{
$this->lecturaInicial = $lecturaInicial;

return $this;
}

/**
* Get lecturaInicial
*
* @return float
*/
public function getLecturaInicial()
{
return $this->lecturaInicial;
}

/**
* Set regularitzacio
*
* @param boolean $regularitzacio
* @return Lectura
*/
public function setRegularitzacio($regularitzacio)
{
$this->regularitzacio = $regularitzacio;

return $this;
}

/**
* Get regularitzacio
*
* @return boolean
*/
public function getRegularitzacio()
{
return $this->regularitzacio;
}

public function rotarImatge($direccio, $plataforma){

if($direccio == 'esquerra'){
shell_exec("convert -rotate -90 ./uploads/".$plataforma."/lectures/lectura_".$this->id."/'".$this->fotografia."' ./uploads/".$plataforma."/lectures/lectura_".$this->id."/'".$this->fotografia."'");
}else{
shell_exec("convert -rotate 90 ./uploads/".$plataforma."/lectures/lectura_".$this->id."/'".$this->fotografia."' ./uploads/".$plataforma."/lectures/lectura_".$this->id."/'".$this->fotografia."'");
}
}
/**
* Constructor
*/
public function __construct()
{
$this->registreAlertes = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
* Add registreAlertes
*
* @param \Aquagest\AlertesabastamentBundle\Entity\RegistreAlertaAbastament $registreAlertes
* @return Lectura
*/
public function addRegistreAlerte(\Aquagest\AlertesabastamentBundle\Entity\RegistreAlertaAbastament $registreAlertes)
{
$this->registreAlertes[] = $registreAlertes;

return $this;
}

/**
* Remove registreAlertes
*
* @param \Aquagest\AlertesabastamentBundle\Entity\RegistreAlertaAbastament $registreAlertes
*/
public function removeRegistreAlerte(\Aquagest\AlertesabastamentBundle\Entity\RegistreAlertaAbastament $registreAlertes)
{
$this->registreAlertes->removeElement($registreAlertes);
}

/**
* Get registreAlertes
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRegistreAlertes()
{
return $this->registreAlertes;
}

/**
* Add factures
*
* @param \Aquagest\ComptabilitatBundle\Entity\FacturaLectura $factures
* @return Lectura
*/
public function addFacture(\Aquagest\ComptabilitatBundle\Entity\FacturaLectura $factures)
{
$this->factures[] = $factures;

return $this;
}

/**
* Remove factures
*
* @param \Aquagest\ComptabilitatBundle\Entity\FacturaLectura $factures
*/
public function removeFacture(\Aquagest\ComptabilitatBundle\Entity\FacturaLectura $factures)
{
$this->factures->removeElement($factures);
}

/**
* Get factures
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFactures()
{
return $this->factures;
}

/**
* Set factura
*
* @param \Aquagest\ComptabilitatBundle\Entity\FacturaLectura $factura
* @return Lectura
*/
public function setFactura(\Aquagest\ComptabilitatBundle\Entity\FacturaLectura $factura = null)
{
$this->factura = $factura;

return $this;
}

/**
* Get factura
*
* @return \Aquagest\ComptabilitatBundle\Entity\FacturaLectura
*/
public function getFactura()
{
return $this->factura;
}
}

JSON дисплей

[{"id":12,"any":2014,"trimestre":1,"lectura":25,"nComptador":{"__initializer__":{},"__cloner__":{},"__isInitialized__":false}},{"id":13,"any":2014,"trimestre":2,"lectura":20,"nComptador":{"__initializer__":{},"__cloner__":{},"__isInitialized__":false}},{"id":14,"any":2014,"trimestre":3,"lectura":10,"nComptador":{"__initializer__":{},"__cloner__":{},"__isInitialized__":false}},{"id":15,"any":2014,"trimestre":4,"lectura":5,"nComptador":{"__initializer__":{},"__cloner__":{},"__isInitialized__":false}},{"id":20,"any":2015,"trimestre":1,"lectura":4,"nComptador":{"__initializer__":{},"__cloner__":{},"__isInitialized__":false}},{"id":21,"any":2015,"trimestre":2,"lectura":3,"nComptador":{"__initializer__":{},"__cloner__":{},"__isInitialized__":false}},{"id":22,"any":2015,"trimestre":4,"lectura":2,"nComptador":{"__initializer__":{},"__cloner__":{},"__isInitialized__":false}}]

0

Решение

Вместо того, чтобы получить объект объекта Lecture, вы можете попробовать это

 $lectures = $this->getDoctrine()
->getRepository('AquagestLecturesBundle:Lectura')
->createQueryBuilder('l')
->join('l.ncomptador','n')
->select('l','n')->orderBy('l.id')->getQuery()->getArrayResult();
return jsonResponse($lectures);
0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]