Created
January 8, 2020 14:19
-
-
Save cybernet/7c3ffc4483d407f9ef7925671da20402 to your computer and use it in GitHub Desktop.
Update CoverPhoto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="companyCoverPhoto", cascade={"persist", "remove"}, orphanRemoval=true) | |
* @ORM\JoinColumn(nullable=false) | |
*/ | |
private $company; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @ORM\OneToOne(targetEntity="App\Entity\CompanyCoverPhoto", mappedBy="company", cascade={"persist", "remove"}, orphanRemoval=true) | |
*/ | |
private $companyCoverPhoto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function showUserCoverPhoto(Request $request, EntityManagerInterface $m, Uploader $up) | |
{ | |
/** @var User $usr */ | |
$usr = $this->getUser(); | |
$form = $this->createForm(CoverPhotoForm::class, $usr); | |
$form->handleRequest($request); | |
if ($form->isSubmitted() && $form->isValid()) { | |
// holds the submitted values iN MeM | |
$c = $form->getData(); | |
/** @var UploadedFile $uploadedFile */ | |
$uploadedFile = $form['imageFile']->getData(); | |
if ($uploadedFile) { | |
$newFilename = $up->uploadCoverImage($uploadedFile, $c->getFilename()); | |
$c->setFilename($newFilename); | |
} | |
$m->persist($c); | |
$m->flush(); | |
return $this->redirectToRoute('show_blog'); | |
} | |
return $this->render('user/cover_image.html.twig', [ | |
'CoverForm' => $form->createView(), | |
'u' => $usr, | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment