miratum
miratum

Reputation: 177

get data from my database table

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

Answers (1)

i.am.michiel
i.am.michiel

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 :

  • make the members public
  • annotate your model with serialization info using JMSSerializerBundle
  • or if you are running php > 5.4 implement the JsonSerializable interface and thus add a jsonSerialize method where you do the conversion yourself.

Upvotes: 1

Related Questions