我只是关于Symfony2中的DQL函数的问题,我有代码:
public function editAction(Request $request, $regkey){
try{
if($request->isMethod('POST')){
$newpassword = $request->request->get('newpassword');
$confirmpassword = $request->request->get('confirmpassword');
$username = $request->request->get('username');
if ($newpassword != $confirmpassword){
return new JsonResponse(['userRegistration' => 'Confirm password is wrong, please make sure your confirm password']);
}
$userRegistrationId = $this->getDoctrineRepo(UserRegistration::class)->getIdbyRegisterKey($regkey);
if ($userRegistrationId == null){
return new JsonResponse(['userRegistration' => 'Registration key is wrong, Please make sure your registration']);
}
$userNameCorrect = $userRegistrationId[0]['user']['username'];
$userid = $userRegistrationId[0]['user']['id'];
if ($username != $userNameCorrect){
return new JsonResponse(['userRegistration' => 'user name is wrong, please insert user name correctly']);
}
$userEntity = $this->getDoctrineRepo(User::class)->find($userid);
$userEntity->setActivate(1);
$userEntity->setActivationDate(new \DateTime());
}
}
catch (Exception $ex){
return new JsonResponse(['errMsg' => $ex], 500);
}
return new JsonResponse(['userRegistration' => 'Validation user success']);
}
有一个$ userRegistrationId,我想删除那些数据,我该如何编码这个问题?
答案 0 :(得分:0)
如果要删除提取到$ userRegistrationId的UserRegistration,则需要获取对象而不是id。您可以使用findOneBy()并使用EntityManager删除该对象。