doubian6241
2017-08-01 17:45
浏览 123
已采纳

在树枝中显示Symfony中JOIN查询的结果

I have 2 tables which are not related by ORM so I do theJOIN as follows:

$dql="SELECT u, o
      FROM BackendBundle:Orders o
      JOIN BackendBundle:Users u
      WITH o.userid=u.id";
$query=$em->createQuery($dql);

When I send the query to twig to show it on the screen it shows me an error.

This is the code in twig:

{% for ordenes in pagination %}
  <td>{{ ordenes.orderid }}</td>
  <td>{{ ordenes.orderdate|date("Y-m-d") }}</td>
{% endfor %}

And the error is this:

Neither the property "orderid" nor one of the methods "orderid()", "getorderid()"/"isorderid()" or "__call()" exist and have public access in class "BackendBundle\Entity\Users"

If I run twig this code:

{{dump(pagination)}}

It correctly shows me what the query returns:

  #currentPageNumber: 3
  #numItemsPerPage: 20
  #items: array:40 [▼
    0 => Orders {#522 ▼
      -orderid: 158
      -orderdate: DateTime {#476 ▶}
      -ordernumber: "FFFFFFFFFFF"
      -customername: "UUUUUUUUUUUU"
      -customeraddress: "OOOOOO"
      -countrycode: "US"
      -shippingaddress: "PPPPPP"
      -status: "Ordered"
      -subtotal: "5.00"
      -shippingcost: "2.82"
      -tax: "0.00"
      -discount: "0.00"
      -totalorder: "7.82"
      -shippingcarrier: "Fedex"
      -userid: "1206"
    }
    1 => Users {#525 ▼
      -id: 1206
      -username: "xxxxxxxxxxxxxx@hotmail.com"
      -yourname: null
      -firstname: "GGGG"
      -lastname: "IIIIII"
      -middlename: ""
      -address: "oooooooooo"
      -address2: ""
      -apartment: ""
      -pobox: ""
      -city: "Monsey"
      -state: "NY"
      -zipcode: "88888888"
      -country: "USA"
      -countrycode: "US"
      -email: "xxxxxxxxxxx@hotmail.com"
      -datein: DateTime {#521 ▶}
    }

My question is how can I show this result in twig ??

图片转代码服务由CSDN问答提供 功能建议

我有2个表与 ORM 无关,所以我做 JOIN 如下:

  $ dql =“SELECT u,o 
 FROM BackendBundle:订单o 
 JOIN BackendBundle:用户u 
 WITH o.userid  = u.id“; 
 $ query = $ em-&gt; createQuery($ dql); 
   
 
 

当我将查询发送到twig以显示它时 在屏幕上显示错误。

这是 twig 中的代码:

  {%for 分页中的ordenes%} 
&lt; td&gt; {{ordenes.orderid}}&lt; / td&gt; 
&lt; td&gt; {{ordenes.orderdate | date(“Ymd”)}}&lt; / td&gt; 
  {%endfor%} 
   
 
 

错误是这样的:

属性“orderid” 也没有其中一种方法“orderid()”, “getorderid()”/“isorderid()”或“__call()”存在并且在“BackendBundle \ Entity \ Users”类中具有公共访问权限

如果我运行 twig 这段代码:

  {{dump(pagination)}} \  ñ <  / pre> 
 
 

它正确显示了查询返回的内容:

  #currentPageNumber:3 
 #numItemsPerPage:20 
 #items:array:  40 [▼
 0 =&gt; 订单{#522▼
 -orderid:158 
 -orderdate:DateTime {#476▶} 
 -ordernumber:“FFFFFFFFFFF”
 -customername:“UUUUUUUUUUUUU”
 -customeraddress:“OOOOOO”
 -countrycode  :“US”
 -shippingaddress:“PPPPPP”
 -status:“Ordered”
 -subtotal:“5.00”
 -shippingcost:“2.82”
 -tax:“0.00”
 -discount:“  0.00“
 -totalorder:”7.82“
 -shippingcarrier:”Fedex“
 -_idid:”1206“
} 
 1 =&gt; 用户{#525▼
 -id:1206 
 -username:“xxxxxxxxxxxxxx@hotmail.com”
 -yourname:null 
 -firstname:“GGGG”
 -lastname:“IIIIII”
 -middlename:  “”
 -address:“oooooooooo”
 -address2:“”
 -apartment:“”
 -pobox:“”
 -city:“Monsey”
 -state:“NY”
  -  邮编:“88888888”
 -country:“USA”
 -countrycode:“US”
 -email:“xxxxxxxxxxx@hotmail.com”
 -datein:DateTime {#521▶} 
} 
 <  / code>  
 
 

我的问题是如何在树枝上显示这个结果?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题