Compare commits

..

3 Commits

Author SHA1 Message Date
5c34c1061c Comment photo is now showed in admin page 2024-07-28 02:54:46 -04:00
14cf8d8fb5 Comment form can now upload image 2024-07-28 02:51:44 -04:00
9cf8c5a6d6 Remove bad line 2024-07-28 02:41:02 -04:00
4 changed files with 19 additions and 4 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/public/uploads
###> symfony/framework-bundle ### ###> symfony/framework-bundle ###
/.env.local /.env.local

View File

@@ -4,6 +4,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed # Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters: parameters:
photo_dir: "%kernel.project_dir%/public/uploads/photos"
services: services:
# default configuration for services in *this* file # default configuration for services in *this* file

View File

@@ -10,6 +10,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField; use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
@@ -46,7 +47,9 @@ class CommentCrudController extends AbstractCrudController
yield TextareaField::new('text') yield TextareaField::new('text')
->hideOnIndex() ->hideOnIndex()
; ;
yield TextField::new('photoFilename') yield ImageField::new('photoFilename')
->setBasePath('/uploads/photos')
->setLabel('Photo')
->onlyOnIndex() ->onlyOnIndex()
; ;

View File

@@ -9,6 +9,7 @@ use App\Repository\CommentRepository;
use App\Repository\ConferenceRepository; use App\Repository\ConferenceRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
@@ -30,14 +31,23 @@ class ConferenceController extends AbstractController
} }
#[Route('/conference/{slug}', name: 'conference')] #[Route('/conference/{slug}', name: 'conference')]
public function show(Request $request, Conference $conference, CommentRepository $commentRepository): Response public function show(
{ Request $request,
Conference $conference,
CommentRepository $commentRepository,
#[Autowire('%photo_dir%')] string $photoDir,
): Response {
$comment = new Comment(); $comment = new Comment();
$form = $this->createForm(CommentType::class, $comment); $form = $this->createForm(CommentType::class, $comment);
$form->handleRequest($request); $form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) { if($form->isSubmitted() && $form->isValid()) {
$comment->setConference($conference); $comment->setConference($conference);
dump($comment); if($photo = $form['photo']->getData()) {
$filename = bin2hex(random_bytes(6)) . '.' . $photo->guessExtension();
$photo->move($photoDir, $filename);
$comment->setPhotoFilename($filename);
}
$this->entityManager->persist($comment); $this->entityManager->persist($comment);
$this->entityManager->flush(); $this->entityManager->flush();