hous
hous

Reputation: 2679

Error when trying to display page in JSON format

I have this error when trying to display page in JSON format but with the html format it works fine

An exception occurred while executing

 'SELECT t0.id AS id1, t0.libProjet AS libProjet2, t0.site AS site3, t0.partceg AS partceg4, t0.datego AS datego5, t0.dateResmisOff AS dateResmisOff6, t0.dateTransfert AS dateTransfert7, t0.nompays_id AS nompays_id8, t0.libTypeProj_id AS libTypeProj_id9, t0.nomclt_id AS nomclt_id10,t0.libContrat_id AS libContrat_id11, t0.libEtatProj_id AS libEtatProj_id12, t0.libEtatOff_id AS libEtatOff_id13 

FROM projet t0 WITH (NOLOCK) WHERE t0.id = ?' with params ["index.json"]:

this is the entity

class projet
{
/**
* @var integer 
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

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

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

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

//....

This is the Controller

public function indexAction()
{
$em = $this->getDoctrine()->getManager();

$entities = $em->getRepository('rexBundle:projet')->findAll();

$repository = $this->getDoctrine()->getRepository('rexBundle:projet');
$query = $repository->createQueryBuilder('t')

->select('t.id','t.libProjet','t.site','t.partceg',
'IDENTITY(t.nompays) AS nompays',
'IDENTITY(t.libTypeProj) AS libTypeProj',
'IDENTITY(t.nomclt) AS nomclt',
'IDENTITY(t.libContrat) AS libContrat',
'IDENTITY(t.libEtatProj) AS libEtatProj',
'IDENTITY(t.libEtatOff) AS libEtatOff',
't.datego',
't.dateResmisOff',
't.dateTransfert')

 ->getQuery();
 $entities = $query->getResult();

 $entity = new projet();
 $form = $this->createCreateForm($entity);

 return array(
 'entities' => $entities,
 'entity' => $entity,
 'form' => $form->createView(),
);
}

Upvotes: 0

Views: 102

Answers (1)

Thomas Shelby
Thomas Shelby

Reputation: 1370

If you want send JSON response, read this article in documentation. http://symfony.com/doc/current/components/http_foundation/introduction.html#creating-a-json-response

Now in your controller you don't send JSON Response, you only render form

Example how send JSON response:

use Symfony\Component\HttpFoundation\Response;

$response = new Response();
$response->setContent(json_encode(array(
    'data' => 123,
)));
$response->headers->set('Content-Type', 'application/json');

Upvotes: 1

Related Questions