2015-06-11 93 views
-1

我想從數據庫查找所有值($ id)的作品,但是當我嘗試使用FindAll()它顯示我下面的錯誤。 雖然退出(\ Doctrine \ Common \ Util \ Debug :: dump($ questions)),此命令會從數據庫生成所有值。 我的錯誤是,當我運行程序它顯示我用於與鍵陣列 密鑰「問題」,「0,1,2,3」不存在AcmeABundle:默認:view.html.twig查看數據庫值使用FindAll()Symfony2

我的觀點.html.twig文件

{% extends 'AcmeABundle:Default:index.html.twig' %} 
    {% block content %} 
    <ul> 
      {% for quiz_table in questions %} 
    <li> {{ questions.question }} 
      {{ questions.choice1 }} 
      {{ questions.choice2 }} 
      {{ questions.choice3 }} 
      {{ questions.answer }} 
</li> 
    {% endfor %} 
    </ul> 
    </div> 
    {% endblock %} 

我的控制器

public function showAction() 
{ 
$repository=$this->getDoctrine()->getRepository('AcmeQuizBundle:QuizTable'); 
$questions=$repository->findAll(); 

    return $this->render('AcmeQuizBundle:Default:view.html.twig',array(
     'questions'=>$questions 
    ) 

); 
} 
+0

我的錯誤是,當我運行程序它示出了用於與鍵「0,1陣列我密鑰「問題」 ,2,3「在AcmeABundle中不存在:默認值:view.html.twig – Anonymous

回答

1

你需要遍歷所有條目

for 循環順序中的每個項目。例如,要顯示在一個變量被稱爲用戶提供的用戶的列表:

<h1>Users</h1> 
<ul> 
    {% for user in users %} 
     <li>{{ user.username|e }}</li> 
    {% endfor %} 
</ul> 

http://twig.sensiolabs.org/doc/tags/for.html

+0

我已添加循環 – Anonymous

+0

它需要如下所示: '{%for quiz_table in questions%} {{quiz_table.question} } {{quizz_table.choice1}} {{qu izz_table.choice2}} {{quizz_table.choice3}} {{quizz_table.answer}} {%ENDFOR%}' –

+0

感謝它解決我的問題@紀堯姆·法希 – Anonymous