Answer the question
In order to leave comments, you need to log in
How to display data in Twig template engine?
Good time. I ran into an unexpected problem while learning Symfony. The Twig template engine throws the following error:
Method "..." for object "..." does not exist in ... at line
{% for all in books %}
<li>{{ all.idBook }}</li>
{% endfor %}
public function BookAction()
{
$repository = $this->getDoctrine()->getRepository('BookBundle:Book');
if (!$repository) {
throw $this->createNotFoundException('No book found');
}
$books = $repository->findAll();
$booksContent = $this->render('BookBundle:Default:book.html.twig', array('books' => $books));
return new Response($booksContent);
}
/**
* @var int
*
* @ORM\Column(name="id_book", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id_book;
public function getBookId() {return $this->id_book;}
array:3 [▼
0 => Book {#376 ▼
#id_book: 1
...
Answer the question
In order to leave comments, you need to log in
do you have a getIdBook() method in entity?
According to your data, the whole picture is not visible, it can be anything
Yes, here the author knows something, you yourself know what ...
if (!$repository) {
throw $this->createNotFoundException('No book found');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question