it gives the error that i wrote on the title. I've used this exact same code before but i doesnt work now. I think i doesnt get the "id" but i dont know why. if i uncomment those comment lines on the controller it opens the photo add window and lets me select a photo but after clicking submit, it doesnt upload. please guys i really need your help. any ideas? I've seen same erorr on stackoverflow here but that solution didnt work for me
*****This is my controller*****
/**
* @Route("/{id}/fotoekle", name="duyurular_fotoekle", methods={"GET","POST"})
*/
public function fotoekle(Request $request, $id, Duyurular $duyurular): Response
{
$form = $this->createForm(DuyurularType::class, $duyurular);
$form->handleRequest($request);
echo ('sefa');
// if ($form->isSubmitted() && $form->isValid()) {
echo ('sefa2');
$file = $request->files->get('image');
$fileName = $this->generateUniqueFileName().'.'.$file->guessExtension();
// dump($request);
// die();
// $file = $duyurular->getFotograf();
// $file = $form->get('fotograf')->getData();
try{
$file->move(
$this->getParameter('fotograflar_directory'),
$fileName
);
}catch (FileException $e){
}
$duyurular->setFotograf($fileName);
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('duyurular_fotoekle', ['id' => $duyurular->getId(),]);
// }
// return $this->render('duyurular/fotoekle.html.twig', [
// 'duyurular' => $duyurular,
// 'form' => $form->createView(),
// 'id' => $duyurular->getId(),
// ]);
}
This is my .html.twig file/ form code
{% block body %}
<h1>{{ duyurular.baslik }}</h1>
<form action="{{ path('duyurular_fotoekle',{'id':id}) }}" method="post" enctype="multipart/form-data">
Select image to upload:
<input name="duyuruid" value="{{ id }}" type="number" readonly>
<input type="file" name="image" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
{% if duyurular.fotograf != null %}
<img src="{{ asset('yuklenen') }}/fotograflar/{{ duyurular.fotograf }}" height="100">
{% endif %}
{% endblock %}