我有一个请求返回具有此结构的内容。
以下是我所拥有的链接:
所以我想打印一些任务领域,但我不知道如何访问它:
得到了这个
<table>
<thead> <!-- En-tête du tableau -->
<tr>
<th>Vague Id</th>
<th>Code Vague</th>
<th>Date Fin Ultime Vague</th>
<th>Mission Id</th>
<th>Enqueteur Id</th>
<th>Mission date rea prev</th>
<th>Mission nom</th>
</tr>
</thead>
{% for resultat in resultats %}
<tr>
<td>{{ resultat.id }}</td>
<td>{{ resultat.codeVague }}</td>
<td>{{ resultat.date_fin_ultime|date('Y-m-d') }}</td>
{% for mission in resultat.mission %}
<td>{{ mission.id }}</td>
<td>{{ mission.enqueteur_id }}</td>
<td>{{ mission.date_rea_prev }}</td>
<td>{{ mission.nom }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
但他不知道野战任务,因为关键是0.我怎么能这样做?感谢
编辑:我用来获取数据的查询:
$sql="SELECT v.id,v.codeVague, v.date_fin_ultime,m
FROM McInvestigatorBundle:Vague v
INNER JOIN McInvestigatorBundle:Enquete e WITH e.vague_id = v.id
INNER JOIN McInvestigatorBundle:Mission m WITH m.id = e.mission_id
INNER JOIN McInvestigatorBundle:Contrat c WITH c.id = m.contrat
INNER JOIN McInvestigatorBundle:User u WITH u.enqueteur_id = e.enqueteur_id
INNER JOIN McInvestigatorBundle:PointDeVente p WITH p.id = e.pdv_id
WHERE v.codeVague =".$wave_code."
AND e.type_id =".$type_id."
AND m.enqueteur_id=".$enq_id."
ORDER BY m.date_rea_prev ASC";
编辑2:我的结果转储
array (size=2)
0 =>
array (size=4)
'missions' =>
object(Mc\InvestigatorBundle\Entity\Mission)[404]
protected 'enqueteur' =>
object(Proxies\__CG__\Mc\InvestigatorBundle\Entity\Enqueteur)[924]
...
protected 'contrat' =>
object(Proxies\__CG__\Mc\InvestigatorBundle\Entity\Contrat)[520]
...
private 'enquetes' =>
object(Doctrine\ORM\PersistentCollection)[524]
...
private 'id' => int 1847050
protected 'enqueteur_id' => int 100384
private 'timestamp_msh' => int 550163591
protected 'is_pack' => boolean true
private 'date_imposee' => boolean true
private 'date_rea_prev' =>
object(DateTime)[55]
...
private 'nom' => string 'INTERMARCHE JUVIGNAC-SUPER-DRIVE' (length=32)
private 'code' => string 'ITM0022' (length=7)
private 'statut' => string '' (length=0)
private 'timestamp_modif' => int 0
private 'date_min' =>
object(DateTime)[387]
...
private 'date_max' =>
object(DateTime)[395]
...
private 'last_modif' => null
private 'date_realisation' => null
private 'heure_realisation' => null
private 'type' => string 'TOURNEE' (length=7)
private 'statut_etat' => string '' (length=0)
private 'statut_validate' => string '' (length=0)
private 'statut_paiement' => string '' (length=0)
private 'statut_factu' => string '' (length=0)
private 'check_bo_date' => null
private 'remuneration' => null
private 'equiv_nbh' => null
private 'date_mise_enligne' => null
private 'frais_type_accord' => int 0
private 'frais_achats' => null
private 'frais_divers' => null
private 'frais_total' => null
private 'date_envoi_dossier' => null
private 'pem_code' => null
'id' => int 152867
'codeVague' => string 'ITM1702A' (length=8)
'date_fin_ultime' =>
object(DateTime)[62]
public 'date' => string '2017-07-04 00:00:00.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Berlin' (length=13)
答案 0 :(得分:0)
您的DQL查询返回所谓的混合结果,混合结果的第一个约定是 FROM子句中提取的对象始终使用键“0”定位。 考虑到这一点,您应该能够以这种方式访问任务对象:
{% for resultat in resultats %}
...
{% for mission in resultat.0 %}
<td>{{ mission.id }}</td>
<td>{{ mission.enqueteur_id }}</td>
<td>{{ mission.date_rea_prev }}</td>
<td>{{ mission.nom }}</td>
{% endfor %}
{% endfor %}
有关纯粹与混合结果的更多信息,请访问:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#pure-and-mixed-results