2016-12-26 46 views
0

我只是在Symfony2中DQL功能出了問題,我有一些代碼:DQL Symfony的2刪除數據

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,我想刪除這些數據,我怎麼能編寫這個問題?

+1

你的意思是刪除'UserRegistration'對象嗎? –

+0

如果您想要刪除UserRegistration,並將其提取到$ userRegistrationId中,則需要獲取object not id。您可以使用findOneBy()和用戶EntityManager來刪除該對象。 –

+0

我的意思是用戶註冊數據不是對象。 @AlvinBunk –

回答

0

如果您想要刪除UserRegistration,並將其提取到$ userRegistrationId中,則需要獲取object not id。您可以使用findOneBy()並使用EntityManager刪除該對象。

+0

謝謝你的回答 –