Skip to content

Instantly share code, notes, and snippets.

@cybernet
Created January 8, 2020 14:19
Show Gist options
  • Save cybernet/7c3ffc4483d407f9ef7925671da20402 to your computer and use it in GitHub Desktop.
Save cybernet/7c3ffc4483d407f9ef7925671da20402 to your computer and use it in GitHub Desktop.
Update CoverPhoto
<?php
/**
* @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="companyCoverPhoto", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\JoinColumn(nullable=false)
*/
private $company;
<?php
/**
* @ORM\OneToOne(targetEntity="App\Entity\CompanyCoverPhoto", mappedBy="company", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $companyCoverPhoto;
<?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