В настоящее время я работаю над базовым c Symfony проектом, чтобы обнаружить эту платформу, мой веб-сайт идентифицирует некоторые французские рэп-альбомы и дает информацию об этом, затем я создал 2 контроллера: «DefaultController» и «AlbumsController». Во-первых, я реализую некоторые функции для отображения некоторых текстов музыки c и использую имена путей для ссылок, и это хорошо работает, но со вторым контроллером я делаю точно такие же вещи, и он не работает. (Извините за плохого энгли sh). В приложении -> проблемный c код DefaultController:
<?php
namespace App\Controller;
use App\Entity\Musique;
use App\Form\AlbumsType;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Controller\AlbumsController;
use App\Repository\AlbumsRepository;
use App\Repository\MusiqueRepository;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Albums;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="index")
*/
public function index()
{
return $this->render('index.html.twig', [
'title' => 'Accueil',
]);
}
/**
* @Route("/albums", name="albums")
*/
public function albums()
{
$repo = $this->getDoctrine()->getRepository(Albums::class);
$albums = $repo->findAll();
return $this->render('albums/index.html.twig', [
'albums' => $albums,
]);
}
/**
* @Route("/musiques", name="musiques")
*/
public function musiques()
{
$repo = $this->getDoctrine()->getRepository(Musique::class);
$musiques = $repo->findAll();
return $this->render('musiques.html.twig', [
'title' => 'Liste des Musiques',
'$musiques' => $musiques,
]);
}
/**
* @Route("/musiques/{id}", requirements={"id": "[1-9]\d*"}, name="randMusique")
* @throws \Exception
*/
public function randomMusique()
{
$random = random_int(1, 100);
$repo = $this->getDoctrine()->getRepository(Musique::class);
$musique = $repo->find($random);
return $this->render('randomMusique.html.twig', [
'musique' => $musique,
]);
}
}
AlbumsController:
<?php
namespace App\Controller;
use App\Entity\Albums;
use App\Form\AlbumsType;
use App\Repository\AlbumsRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/albums")
*/
class AlbumsController extends AbstractController
{
/**
* @Route("/", name="albums_index", methods={"GET"})
*/
public function index(AlbumsRepository $albumsRepository): Response
{
return $this->render('albums/index.html.twig', [
'albums' => $albumsRepository->findAll(),
]);
}
/**
* @Route("/new", name="album_new", methods={"GET","POST"})
*/
public function new(Request $request): Response
{
$album = new Albums();
$form = $this->createForm(AlbumsType::class, $album);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($album);
$entityManager->flush();
return $this->redirectToRoute('albums_index');
}
return $this->render('albums/new.html.twig', [
'album' => $album,
'formAlbum' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="albums_show", methods={"GET"})
*/
public function show(Albums $album): Response
{
return $this->render('albums/show.html.twig', [
'album' => $album,
]);
}
/**
* @Route("/{id}/edit", name="albums_edit", methods={"GET","POST"})
*/
public function edit(Request $request, Albums $album): Response
{
$form = $this->createForm(AlbumsType::class, $album);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('albums_index');
}
return $this->render('albums/edit.html.twig', [
'album' => $album,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="albums_delete", methods={"DELETE"})
*/
public function delete(Request $request, Albums $album): Response
{
if ($this->isCsrfTokenValid('delete'.$album->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($album);
$entityManager->flush();
}
return $this->redirectToRoute('albums_index');
}
}
base. html .twig:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}Projet — PHP{% endblock %}</title>
<link rel="stylesheet" href="https://bootswatch.com/4/darkly/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="{{ asset('css/style.css')}}">
{% block stylesheets %}{% endblock %}
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light">
<a class="navbar-brand" href="/">France-Rap</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor03"
aria-controls="navbarColor03" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarColor03">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="{{ path('index') }}">Accueil</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ path('albums') }}">Liste des Albums</a>
</li>
{#
<li class="nav-item">
<a class="nav-link" href="{{ path('musiques') }}">Liste des Musiques</a> // The path isn't working
</li>
<li class="nav-item">
<a class="nav-link" href="{{ path('randMusique') }}">Musique Aléatoire</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ path('album_new') }}">Créer un Album</a>
</li>
#}
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
{% block search %}{% endblock %}
</div>
</nav>
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
</body>
</html>
Это ошибка: Ошибка рендеринга Результат команды: php Отладка bin / console: музыка маршрутизатора