[英]Symfony Twig variable not recognized (Variable does not exist)
這在幾個小時前工作正常,我從數據庫中獲取數據並簡單地將其顯示在 Twig 的表中。 這是 controller ,我從中獲取具有我的實體“Cours”的變量實例
/**
* @Route("/listeCours", name="liste_cours")
*/
public function index()
{
$lstCours = $this->getDoctrine()
->getRepository('App:Cours')
->findAll();
return $this->render('liste_cours/index.html.twig', ['lstCours' => $lstCours]);
}
我將實體“Cours”的存儲庫中的數據保存在變量“lstCours”中,這是我稍后將在 twig 中調用的變量,
{% for cours in lstCours %}
<tr>
<td>{{ cours.nom }}</td>
<td>{{ cours.type }}</td>
<td>{{ cours.description }}</td>
<td>{{ cours.prix }}</td>
<td>
<button class="btn_apt btn"><a href="">Ajouter</a></button>
</td>
</tr>
編譯器不斷顯示異常,指出變量 (lstCours) 不存在。
先感謝您。
當你想調試你的 Twig 上下文時,你可以使用:
{{ dump(_context) }}
它將向您顯示模板中的所有可用變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.