Twig for 循环在 MySQL 数据库中找不到记录

Twig for loop can't find record in MySQL database

我的 for 循环似乎无法在我的数据库中找到任何记录。

我的循环:

            {% for school in scholen %}
                <li>{{ scholen.naam|e }}</li>
            {% else %}
                <li>no user found</li>
            {% endfor %}

My result.

如果我删除 else 它只是 'empty' 在 "Scholen"

下面

这是我的控制器

namespace App\Controller;


use App\Entity\School;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class SchoolController extends AbstractController
{
    /**
     * @Route ("/scholen", name="scholen")
     * Method ({"GET", "POST"})
     */

    public function schoolgegevens()
    {
        $scholen = $this->getDoctrine()
            ->getRepository(School::class);


        return $this->render("security/school.html.twig", ["scholen" => $scholen]);
    }

} 

My database table "Scholen".

看看这段代码:

        $scholen = $this->getDoctrine()
            ->getRepository(School::class);

$scholen 包含您的存储库,而不是您的数据。你必须做类似

的事情
    public function schoolgegevens(SchoolRepository $schoolRepository)
    {
        $scholen = $schoolRepository->findAll();

        return $this->render("security/school.html.twig", ["scholen" => $scholen]);
    }