I am working in Symfony - When I am performing an action to delete a user I am receiving the following error messages:
[Semantical Error] line 0, col 7 near 'WHERE u.id =': Error: Class 'WHERE' is not defined.
500 Internal Server Error - QueryException
1 linked Exception:
QueryException »
1/2 QueryException: DELETE WHERE u.id = :id
2/2 QueryException: [Semantical Error] line 0, col 7 near 'WHERE u.id =': Error: Class 'WHERE' is not defined.
Admin Controller
/**
* @Route("/admin/user/delete/{id}", name="admin_user_delete")
* @Template
*/
public function deleteAction($id)
{
$dispatcher = $this->container->get('event_dispatcher');
$this->get('users')->delete($id);
// create the user event and dispatch it
$event = new UserEvent($id);
$dispatcher->dispatch(UserEvents::USER_DELETED, $event);
$this->get('session')->getFlashBag()->add('notice-success', 'User deleted successfully.');
return $this->redirect($this->generateUrl('admin_user_list'));
}
User.php Service
public function delete($id)
{
$this->repository->delete($id);
}
User Repository
public function delete($id)
{
$qb = $this->getEntityManager()->createQueryBuilder('u');
$qb->delete()
->andWhere($qb->expr()->eq('u.id', ':id'))
->setParameter(':id', $id)
->getQuery()
->getResult();
}
:character in thesetParameter()call. docs.doctrine-project.org/projects/doctrine-orm/en/latest/…