use App\Entity\Movie;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class MoviesController extends AbstractController
{
#[Route('/movies', name: 'movies')]
public function index(): Response
{
return $this->render('movies/index.html.twig');
}
So if you followed along with the tutorial - in your MoviesController file you would have created a $movies DB query - something like $movies = $repository->findAll()
You need to pass that along with the render method like this...
return $this->render('movies/index.html.twig', ['movies' => $movies,]);
Seems strange that this is missing from the MoviesController file in git repo
Variable "movies" does not exist. ExceptionStack Trace Twig\Error\ RuntimeError in E:\dev\htdocs_link\movies\templates\movies\index.html.twig (line 7) {% block body %}
Created by Code With DaryMovies Review ({{ movies|length }})
MoviesController.php <?php
namespace App\Controller;
use App\Entity\Movie; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route;
class MoviesController extends AbstractController {
} ?>
index.html.twig full code
{% extends "./base.html.twig" %}
{% block body %}
Movies Review ({{ movies|length }})
Created by Code With Dary{% endblock %}
base.html.twig becase we extended class
<!DOCTYPE html>
i had the same problem - 3 hrs into the tutorial and thought i hit a road block...
However a quick search on symfony website (https://symfony.com/doc/current/templates.html#creating-templates) shows you need to pass the dynamic variables with the render function
So if you followed along with the tutorial - in your
MoviesController
file you would have created a $movies DB query - something like$movies = $repository->findAll()
You need to pass that along with the render method like this...
return $this->render('movies/index.html.twig', ['movies' => $movies,]);
Seems strange that this is missing from the
MoviesController
file in git repoHope that helps.