<tfoot id='leo2x'></tfoot>

        <i id='leo2x'><tr id='leo2x'><dt id='leo2x'><q id='leo2x'><span id='leo2x'><b id='leo2x'><form id='leo2x'><ins id='leo2x'></ins><ul id='leo2x'></ul><sub id='leo2x'></sub></form><legend id='leo2x'></legend><bdo id='leo2x'><pre id='leo2x'><center id='leo2x'></center></pre></bdo></b><th id='leo2x'></th></span></q></dt></tr></i><div id='leo2x'><tfoot id='leo2x'></tfoot><dl id='leo2x'><fieldset id='leo2x'></fieldset></dl></div>

        <small id='leo2x'></small><noframes id='leo2x'>

        <legend id='leo2x'><style id='leo2x'><dir id='leo2x'><q id='leo2x'></q></dir></style></legend>
          <bdo id='leo2x'></bdo><ul id='leo2x'></ul>

        Symfony 2 Doctrine 导出到 JSON

        Symfony 2 Doctrine export to JSON(Symfony 2 Doctrine 导出到 JSON)

        <small id='ESJj0'></small><noframes id='ESJj0'>

      1. <i id='ESJj0'><tr id='ESJj0'><dt id='ESJj0'><q id='ESJj0'><span id='ESJj0'><b id='ESJj0'><form id='ESJj0'><ins id='ESJj0'></ins><ul id='ESJj0'></ul><sub id='ESJj0'></sub></form><legend id='ESJj0'></legend><bdo id='ESJj0'><pre id='ESJj0'><center id='ESJj0'></center></pre></bdo></b><th id='ESJj0'></th></span></q></dt></tr></i><div id='ESJj0'><tfoot id='ESJj0'></tfoot><dl id='ESJj0'><fieldset id='ESJj0'></fieldset></dl></div>

          <tbody id='ESJj0'></tbody>

            <legend id='ESJj0'><style id='ESJj0'><dir id='ESJj0'><q id='ESJj0'></q></dir></style></legend>
              <bdo id='ESJj0'></bdo><ul id='ESJj0'></ul>

                <tfoot id='ESJj0'></tfoot>
                  本文介绍了Symfony 2 Doctrine 导出到 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Symfony 2 和 Doctrine 2 为 iOS 应用程序创建 Web 服务 (JSON).

                  I'm using Symfony 2 with Doctrine 2 to create a web service(JSON) for an iOS app.

                  要获取我的实体,我会这样做:

                  To fetch my entity i do:

                  $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 响应?


                  How can i create a json response ?

                  亲切的问候,卡瑙丹

                  var_dump($articles) =

                  var_dump($articles) =

                  array(18) {
                     [0]=>
                       object(UdoPaddujourBundleEntityMenuArticle)#50 (4) {
                      ["id":"UdoPaddujourBundleEntityMenuArticle":private]=>
                      int(1)
                      ["name":"UdoPaddujourBundleEntityMenuArticle":private]=>
                      string(17) "My Article Name 1"
                      ["description":"UdoPaddujourBundleEntityMenuArticle":private]=>
                      string(26) "My Article Description 1"
                      ["price":"UdoPaddujourBundleEntityMenuArticle":private]=>
                      float(20)
                      }
                     [1]=> ...
                  

                  - 稍后编辑

                  如何遍历所有属性名称"?这就是我所拥有的:

                  - LATER EDIT

                  How can i loop through all the "property names" ? This is what i've got:

                  $myarray=array(); 
                  $myArray["name"]=array(); 
                  $myArray["description"]=array(); 
                  foreach($articles in $article) 
                  { 
                    array_push($myArray["name"], $article->getName());
                    array_push($myArray["description"], $article->getDescription()); 
                  }
                  

                  推荐答案

                  如果你使用学说查询,你也可以这样做:

                  If you use a doctrine query you can also do this:

                  $em = $this->getDoctrine()->getEntityManager();
                  $query = $em->createQuery('SELECT ma FROM UdoPaddujourBundle:MenuArticle ma ...etc');
                  $myArray = $query->getArrayResult();
                  

                  然后使用 json_encode($myArray);

                  参见 这里了解更多详情.

                  这篇关于Symfony 2 Doctrine 导出到 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  When should use doctrine ORM and when zend-db-table?(什么时候应该使用学说 ORM,什么时候应该使用 zend-db-table?)
                  Doctrine - self-referencing entity - disable fetching of children(Doctrine - 自引用实体 - 禁用获取子项)
                  Doctrine 2, query inside entities(原则 2,实体内部查询)
                  Complex WHERE clauses using the PHP Doctrine ORM(使用 PHP Doctrine ORM 的复杂 WHERE 子句)
                  Doctrine - OneToMany relation, all result row doesn#39;t fetch in object(Doctrine - OneToMany 关系,所有结果行不获取对象)
                  Doctrine and unrefreshed relationships(教义和未更新的关系)

                  <small id='rb6Nl'></small><noframes id='rb6Nl'>

                  <i id='rb6Nl'><tr id='rb6Nl'><dt id='rb6Nl'><q id='rb6Nl'><span id='rb6Nl'><b id='rb6Nl'><form id='rb6Nl'><ins id='rb6Nl'></ins><ul id='rb6Nl'></ul><sub id='rb6Nl'></sub></form><legend id='rb6Nl'></legend><bdo id='rb6Nl'><pre id='rb6Nl'><center id='rb6Nl'></center></pre></bdo></b><th id='rb6Nl'></th></span></q></dt></tr></i><div id='rb6Nl'><tfoot id='rb6Nl'></tfoot><dl id='rb6Nl'><fieldset id='rb6Nl'></fieldset></dl></div>
                    <tbody id='rb6Nl'></tbody>

                  • <legend id='rb6Nl'><style id='rb6Nl'><dir id='rb6Nl'><q id='rb6Nl'></q></dir></style></legend>
                    • <tfoot id='rb6Nl'></tfoot>
                          • <bdo id='rb6Nl'></bdo><ul id='rb6Nl'></ul>