user3165474 user3165474 - 7 months ago 20
MySQL Question

Delete from database in Symfony 2

I am trying to use a delete function for Symfony 2, which gives me an error


path: /homepage/delete_users/{id}
defaults: {_controller: HomeHomepageBundle:Default:deleteuser}
methods: [GET, POST]


public function deleteuseraction(Users $users)
$em = $this->getDoctrine()->getManager();
$users = $em -> getRepository('LoginLoginBundle:Users')->find($idusers);
$em-> remove($users);
$em -> flush();

return $this->redirectToroute('home_homepage_userlist');


<a href="{{ path('home_homepage_deleteuser') }}"
class="btn btn-danger pull-right">Delete</a>



I can see at least 5 issues here.

  • it should be DefaultController.php instead of Defaultcontroller.php
  • it should be deleteuserAction instead of deleteuseraction
  • (Users $users) argument is incorrect unless you use param converting (you don't provide info about if you do). If so, then you're overriding this variable later which doesn't make sense.
  • $idusers is undefined
  • You do not pass user ID to {{ path('home_homepage_deleteuser') }}

So there is a lot of work to do here. Also you don't even tell us what is the error, so there may be several other issues.