Php Symfony2:FOSUserBundle删除操作错误
对Symfony2来说相当陌生;我现在使用FOSUserBundle作为我的用户提供者。因为它没有为删除操作提供控制器,所以我写了自己的:Php Symfony2:FOSUserBundle删除操作错误,php,symfony,fosuserbundle,Php,Symfony,Fosuserbundle,对Symfony2来说相当陌生;我现在使用FOSUserBundle作为我的用户提供者。因为它没有为删除操作提供控制器,所以我写了自己的: /** * Delete user * * @param integer $id * * @Route("/delete/{id}") * * @return RedirectResponse */
/**
* Delete user
*
* @param integer $id
*
* @Route("/delete/{id}")
*
* @return RedirectResponse
*/
public function deleteAction($id)
{
$em = $this->getDoctrine()->getManager();
$um = $this->get('fos_user.user_manager');
$user = $um->findUserBy(array(
'id' => $id
)
);
$em->remove($user);
$em->flush();
return new RedirectResponse("star9988_user_user_index");
}
并添加了指向“我的模板”路径的链接:
<a href="{{ path('star9988_user_user_delete', {'id': user.id}) }}">
奇怪的是,我得到了相同的结果:从数据库中删除了实体
由于某种原因,我的路线似乎没有通过参数
调试-选择t0.username作为username1,选择t0.username\u规范作为
用户名\u规范2,t0.email作为email3,t0.email\u规范作为
电子邮件_canonical4,t0.enabled AS enabled 5,t0.salt AS salt 6,
t0.密码为密码7,t0.最后登录为最后登录8,t0.锁定为
锁定9,t0。到期为到期10,t0。到期为到期11,
t0.确认令牌作为确认令牌12,
t0.password_requested_at AS password_requested_at 13,t0.roles AS
角色14,t0。凭据已过期,因为凭据已过期15,
t0.credentials\u expire\u at AS credentials\u expire\u at 16,t0.id AS id17,
t0.FirstName作为FirstName18,t0.LastName作为LastName19,t0.creditLimit
作为creditLimit20,t0.creditAvailable作为creditAvailable21,
t0.账户余额作为账户余额22,t0.返利作为返利23,
t0.parent作为来自StarUsers t0的parent24,其中t0.id=?限制1
尝试将id设置为必需参数,如: 您还可以检入用户已加载的代码:
/** @var \Star9988\ModelBundle\Entity\User $user */
$user = $this->getDoctrine()->getRepository('ModelBundle:User')->find($id);
if (!$user instanceof User) {
throw new NotFoundHttpException('User not found for id ' . $id);
}
我希望它能有所帮助。尝试将id设置为必需的参数,如: 您还可以检入用户已加载的代码:
/** @var \Star9988\ModelBundle\Entity\User $user */
$user = $this->getDoctrine()->getRepository('ModelBundle:User')->find($id);
if (!$user instanceof User) {
throw new NotFoundHttpException('User not found for id ' . $id);
}
我希望这会有帮助。当你有了用户管理器
$um = $this->container->get('fos_user.user_manager')
您可以在获得如下用户操作后使用删除:
$um->deleteUser($user);
但是您需要先检查用户是否为空。当您获得用户管理器时
$um = $this->container->get('fos_user.user_manager')
您可以在获得如下用户操作后使用删除:
$um->deleteUser($user);
但您需要先检查用户是否为空。FOSUserBundle附带一个用户管理器,它允许您执行所有这些操作:FOSUserBundle附带一个用户管理器,它允许您执行所有这些操作: