[英]Adding debug traces to Symfony 3.4 twig templates during/after render
[英]Symfony 3.4 : Render multiple array in twig
我得到了一個帶有CollectionType的表單,該表單在SQLite數據庫中存儲了一個數組,這是在控制器中返回的實體對象的結構:
Expertations {#666 ▼
-id: 9
-date: DateTime @1536749818 {#653 ▶}
-client: 1
-status: 0
-price: 0.0
-expiration: DateTime @1536749818 {#650 ▶}
-tipo: 1
-kw: 12
-piani_casa: 2
-riscaldamento: "1"
-opere_murarie: false
-trifase: false
-sconto: 10.0
-level: 1
-square_meters: 140
-floor: array:6 [▼
0 => 1
1 => 1
2 => 2
3 => 2
4 => 2
5 => 2
]
-ambient: array:6 [▼
0 => Rooms {#671 ▼
-id: 10
-name: "Cucina"
-level: 1
-sq_meter_from: 0.0
-sq_meter_to: 999.0
-punti_prese: 5
-punti_luce: 1
-prese_tv: 1
}
1 => Rooms {#649 ▶}
2 => Rooms {#670 ▶}
3 => Rooms {#669 ▶}
4 => Rooms {#649 ▶}
5 => Rooms {#668 ▶}
]
-name: array:6 [▼
0 => "Cucina"
1 => "Soggiorno"
2 => "Corridoio"
3 => "Camera Padronale"
4 => "Camera Figlia"
5 => "Bagno"
]
-pp: array:6 [▼
0 => 5
1 => 4
2 => 2
3 => 4
4 => 4
5 => 2
]
-pl: array:6 [▼
0 => 1
1 => 1
2 => 2
3 => 1
4 => 1
5 => 2
]
-pt: array:6 [▼
0 => 1
1 => 1
2 => 0
3 => 1
4 => 1
5 => 0
]
-num_circuiti: 5
-num_prese_telefono_dati: 3
-illum_sicurezza: 2
-spd: 1
-imp_ausiliari: 1
}
這應該在樹枝模板中以表格的形式呈現,許多數據是使用{{ item.string }}
這樣的簡單數組訪問來檢索的。 字段名為floor, ambient, name, pp, pl, pt
的字段應顯示在項目的一行中(在此示例中,您應該看到所有元素都包含5個鍵)。
我曾嘗試像往常一樣訪問該數組,但在嘗試訪問實際上是整數的鍵時遇到錯誤(不可以嗎?)
這是不起作用的循環的樹枝:
{% for items in item %}
<tr>
<td>{{ items.floor }}</td>
<td>{{ items.ambient }}</td>
<td>{{ items.name }}</td>
<td>{{ items.pp }}</td>
<td>{{ items.pl }}</td>
<td>{{ items.pt }}</td>
</tr>
{% endfor %}
返回的錯誤是: Impossible to access an attribute ("floor") on a integer variable ("1").
預期的行為:
這些項目應顯示在表格中,例如:第一行,顯示floor.0
值, ambient.0.name, name.0
值, pp.0
值, pl.0
值, pt.0
值, pt.0
列等..
有人會提供解決方案以正確呈現嗎?
對於單個Expertations對象(名為yourObject),循環應如下所示:
{% for key in yourObject.floor|keys %}
<tr>
<td>{{ yourObject.floor[key] }}</td>
<td>{{ yourObject.ambient[key] }}</td>
<td>{{ yourObject.name[key] }}</td>
<td>{{ yourObject.pp[key] }}</td>
<td>{{ yourObject.pl[key] }}</td>
<td>{{ yourObject.pt[key] }}</td>
</tr>
{% endfor %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.