Compare commits
3 Commits
fdae2ae025
...
5c34c1061c
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c34c1061c | |||
| 14cf8d8fb5 | |||
| 9cf8c5a6d6 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
/public/uploads
|
||||
|
||||
###> symfony/framework-bundle ###
|
||||
/.env.local
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# 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
|
||||
parameters:
|
||||
photo_dir: "%kernel.project_dir%/public/uploads/photos"
|
||||
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
|
||||
@@ -10,6 +10,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
@@ -46,7 +47,9 @@ class CommentCrudController extends AbstractCrudController
|
||||
yield TextareaField::new('text')
|
||||
->hideOnIndex()
|
||||
;
|
||||
yield TextField::new('photoFilename')
|
||||
yield ImageField::new('photoFilename')
|
||||
->setBasePath('/uploads/photos')
|
||||
->setLabel('Photo')
|
||||
->onlyOnIndex()
|
||||
;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Repository\CommentRepository;
|
||||
use App\Repository\ConferenceRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -30,14 +31,23 @@ class ConferenceController extends AbstractController
|
||||
}
|
||||
|
||||
#[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();
|
||||
$form = $this->createForm(CommentType::class, $comment);
|
||||
$form->handleRequest($request);
|
||||
if($form->isSubmitted() && $form->isValid()) {
|
||||
$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->flush();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user