I am building a bundle for uploading many photos.
I use a table to display my photo's forms.
My problem is, when I click on "Modifier" nothing is done if I didn't change "Activé" or "Titre".
public function ajaxEditPhotoAction(Request $request, $id) {
$error = null;
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository("FDMFileUploaderBundle:Photo");
$photo = $repository->find($id);
$form = $this->get('form.factory')->create(new PhotoType(), $photo);
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
$em->flush();
}
else {
$error = "Mauvaise donnée";
}
}
else {
$error = "Wrong Method";
}
return $this->render('FDMFileUploaderBundle:Default:editPhoto.html.twig', array(
"error" => $error
)
);
}
If I had this line after isValid()
, that's work but when "Activé" or "Titre" are changed, my photos are uploaded twice.
$photo->upload();
How I can force an upload if my attribute which are persisted in my entity are not changed?
I have taken a look in doctrine annotation but, I didn't find solution.
Ajax submit
var data = new FormData(this);
$.ajax({
type: "POST",
url: url,
data: data,
contentType: false,
cache: false,
processData:false,
success: function(data) {
alert("Success");
},
error: function(xhr, textStatus, errorThrown) {
alert("Error "+xhr+textStatus+errorThrown);
}
});