Dzień dobry, mam pewien problem z widocznością zmiennej w instrukcji warunkowej sprawdzającej walidację formularza, chodzi o zmieną "$item->getPhoto()". A co chcę zrobić? W instrukcji warunkowej chcę usunąc te zdjęcie z folderu o podanej nazwie i zamiast niego, wstawić nowe zdjęcie. Ciekawi Mnie dlaczego tak się dzieje. Dodam tylko, że inne wartości z encji(id, name itp.) są dostępne.
public function editProductAction(Request $request, $id){
$photo = array();
$em = $this->getDoctrine()->getManager();
$item = $em->getRepository('AppBundle:Item')->find($id);
$form = $this->createForm(EditProductForm::class, $item);
$form->handleRequest($request);
//return new Response($item->getPhoto()); jest
if($form->isValid() && $form->isSubmitted()){
//return new Response($item->getPhoto()); nie ma
if($form['photo']){
$file = $item->getPhoto();
$filename = $this->get('app.file_uploader')->upload($file);
$item->setPhoto($filename);
}
$em->persist($item);
$em->flush();
return $this->redirectToRoute('editProduct', array('id' => $id));
}
return $this->render('admin/product/editProduct.html.twig', [
'form' => $form->createView(),
'photo' => $item->getPhoto()
]);
}
/**
* @var string
* @ORM\Column(name="photo", type="string", length=255)
*
* @Assert\File(mimeTypes={ "image/jpeg" })
*/
private $photo;
public function getPhoto()
{
return $this->photo;
}
public function setPhoto($photo)
{
$this->photo = $photo;
return $this;
}