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 ###
|
###> symfony/framework-bundle ###
|
||||||
/.env.local
|
/.env.local
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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()
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user