added validator

This commit is contained in:
2021-05-30 20:30:01 +02:00
parent cc470de716
commit c39ac0d299
9 changed files with 183 additions and 24 deletions

View File

@@ -2,17 +2,38 @@
namespace App\Controller;
use App\Entity\Blog;
use App\Repository\BlogRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class BlogController
* @package App\Controller
*/
class BlogController extends AbstractController
{
#[Route('/', name: 'blog')]
public function index(): Response
{
return $this->render('blog/index.html.twig', [
'controller_name' => 'BlogController',
]);
}
#[Route('/', name: 'blogs')]
public function index(BlogRepository $blogRepository): Response
{
return $this->render('blog/index.html.twig', [
'blogs' => $blogRepository->findAll()
]);
}
/**
* @param $id
* @param \App\Repository\BlogRepository $blogRepository
*
* @return \Symfony\Component\HttpFoundation\Response
*/
#[Route('/blog/{id}', name: 'blog')]
public function show($id, BlogRepository $blogRepository): Response
{
return $this->render('blog/show.html.twig', [
'blog' => $blogRepository->findOneBy(['id' => $id])
]);
}
}