I am using Symfony 2 with Doctrine 2 to create a web service (JSON) for an iOS application.
To get my essence, I do:
$articles = $this->getDoctrine()->getRepository('UdoPaddujourBundle:MenuArticle')->findAll();
I must tell you that:
$article = array(); $article = $articles->toArray();
Gives me the following error:
Fatal error: Call to a member function toArray() on a non-object
The same thing happens with
$article = $articles->exportTo('json');
How can I create a json response?
Regards, Cearnau Dan
Edit: var_dump ($ articles) =
array(18) { [0]=> object(Udo\PaddujourBundle\Entity\MenuArticle)#50 (4) { ["id":"Udo\PaddujourBundle\Entity\MenuArticle":private]=> int(1) ["name":"Udo\PaddujourBundle\Entity\MenuArticle":private]=> string(17) "My Article Name 1" ["description":"Udo\PaddujourBundle\Entity\MenuArticle":private]=> string(26) "My Article Description 1" ["price":"Udo\PaddujourBundle\Entity\MenuArticle":private]=> float(20) } [1]=> ...
- LATER EDIT
How can I view all "property names"? This is what I have:
$myarray=array(); $myArray["name"]=array(); $myArray["description"]=array(); foreach($articles in $article) { array_push($myArray["name"], $article->getName()); array_push($myArray["description"], $article->getDescription()); }
json php web-services symfony doctrine
Dan Cearnau Aug 10 2018-11-11T00: 00Z
source share