I am trying to get all values from database Find($id) works but when i try to use FindAll() it shows me following error. Although exit(\Doctrine\Common\Util\Debug::dump($questions)) this command generates all values from database . My error is when i run the program it shows me Key "question" for array with keys "0, 1, 2, 3" does not exist in AcmeABundle:Default:view.html.twig
My view.html.twig file
{% 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 %}
My Controller
public function showAction()
{
$repository=$this->getDoctrine()->getRepository('AcmeQuizBundle:QuizTable');
$questions=$repository->findAll();
return $this->render('AcmeQuizBundle:Default:view.html.twig',array(
'questions'=>$questions
)
);
}
you need to loop over all items
for Loop over each item in a sequence. For example, to display a list of users provided in a variable called users:
http://twig.sensiolabs.org/doc/tags/for.html