Reputation: 177
I want to get data from my database table "Client",but I get this result:
[{},{},{}]
this is my code:
<?php
namespace OP\OPBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use OP\OPBundle\Entity\Client;
class ClientAPIController extends Controller
{
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$personne = $em->getRepository('OPOPBundle:Client')->findAll();
// $personne_tab=array();
// $personne_tab['nom']=$personne->getNom();
// $personne_tab['prenom']=$personne->getPrenom();
// $personne_tab['id']=$personne->getId();
$personntojson= json_encode($personne);
return $this->render('OPOPBundle:ClientAPI:index.html.twig', array(
'reponse'=> $personntojson
)); }
this is index.html.twig:
{{reponse}}
Upvotes: 0
Views: 137
Reputation: 10404
Quite simple. json_encode
will only present/convert the public
available data. All the members in the object are probably private.
You can either :
JsonSerializable
interface and thus add a jsonSerialize
method where you do the conversion yourself. Upvotes: 1