I have this code on listDevice.html.twig
template.
$.ajax({
type: "GET",
url: "http://dev/app_dev.php/device/" + window.id + "/remove",
crossDomain: false,
dataType: "html",
error: function(data) {
console.log("Error in Processing-----" + data.status);
}
});
The code is triggered when someone click on delete
button (doesn't matter). And this is the function that handle the deletion at DeleteController.php
:
/**
* @Route("/device/{id}/remove", name="device_remove")
* @param integer $id
* @param Request $request
* @Method({"GET"})
* @Template()
* @Security("has_role('ROLE_ADMIN')")
* @return array
*/
public function removeAction(Request $request, $id = null)
{
$em = $this->getDoctrine()->getManager();
$can_delete = $em->getRepository('DeviceBundle:UnassignedDevices')->findBy(array('id' => $id));
if (count($can_delete) == 0) {
$driverHasDevice = $em->getRepository("DeviceBundle:DriverHasDevice")->findOneBy(array('device' => $id));
$deviceToRemove = $em->getRepository("DeviceBundle:Device")->findOneBy(array('id' => $id));
if ($driverHasDevice) {
$em->remove($driverHasDevice);
}
$em->remove($deviceToRemove);
$em->flush();
$flashMessage = $this->get('translator')->trans('delete.success', array('%element%' => 'device'));
}
else {
$flashMessage = $this->get('translator')->trans('devices.messages.driver.assigned');
}
$this->get('session')->getFlashBag()->add('message', $flashMessage);
return $this->redirect($this->generateUrl('device_list'));
}
Both works fine, I mean when I click on delete
button the route matches and the code is executed but the redirect, this line, $this->redirect($this->generateUrl('device_list'));
never happen, why is that? How I can fix this?