我正在使用Symfony 2和Doctrine 2为iOS应用程序创建Web服务(
JSON).
要获取我的实体我做:
$articles = $this->getDoctrine()->getRepository('UdoPaddujourBundle:MenuArticle')->findAll();
我必须告诉你:
$article = array(); $article = $articles->toArray();
给我以下错误:
Fatal error: Call to a member function toArray() on a non-object
同样的事情发生了
$article = $articles->exportTo('json');
我怎样才能创建一个json响应?
亲切的问候,
Cearnau Dan
编辑:
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]=> ...
– 稍后编辑
$myarray=array(); $myArray["name"]=array(); $myArray["description"]=array(); foreach($articles in $article) { array_push($myArray["name"],$article->getName()); array_push($myArray["description"],$article->getDescription()); }