can't 'convert Doctrine2 fetchAll() result to JSON in zf2

For programming and general questions on Zend Framework
Post Reply
pani9236
Posts: 2
Joined: Fri Oct 04, 2013 6:33 am

can't 'convert Doctrine2 fetchAll() result to JSON in zf2

Post by pani9236 » Fri Oct 04, 2013 6:40 am

I trying to learn the basic things so that I can build RESTFull Service API in coming days . Now , I am trying to get the doctrine fetch All() result in to json but failing to do so. mys API client ( backbone.js ) is working fine and it is result but showing empty objects

my controller code goes like this

Code: Select all

public function getList() {

        $repository = $this->getEntityManager()->getRepository('Application\Entity\Test');

        $posts = $repository->findAll();

      echo var_dump((array)$posts);

      header('Access-Control-Allow-Origin:*');

     return new JsonModel($posts);
    }
and outpu for var_dump

array(2) {
[0]=>
object(Application\Entity\Test)#339 (2) {
["id":"Application\Entity\Test":private]=>
int(2)
["name":"Application\Entity\Test":private]=>
string(5) "Kumar"
}
[1]=>
object(Application\Entity\Test)#340 (2) {
["id":"Application\Entity\Test":private]=>
int(1)
["name":"Application\Entity\Test":private]=>
string(8) "Panindra"
}

}

and JSONModel output is

Code: Select all

[{},{}]
please , gudie me what i am missing ,, i tried toArray() but it showing cant function on non object

Post Reply