Binding entities to query parameters only allowed for entities have an identifier #6959

Closed
opened 2026-01-22 15:42:09 +01:00 by admin · 0 comments
Owner

Originally created by @yassineMessaoud9 on GitHub (Apr 10, 2022).

I am using a Symfony 4 project, and I want to change the user password, so I created a method in my repository and called it to the controller, but this error it diplay to me,

Binding entities to query parameters only allowed for entities that have an identifier.
Repository

     {
        $dql = <<<DQL
        SELECT u
        FROM App\Entity\Utilisateur u
         WHERE u.email = :email
        AND u.password = :password
         DQL;
 
    return  $this->getEntityManager()->createQuery($dql)
             ->setParameters(['email' => $email, 'password' => $password])
             ->getSingleScalarResult();

Controller

 * @Route("/Reset", name="Reset")
 * Method({"GET"})
 */
public function New(
    Request $request,
    UtilisateurRepository $URe,
    UserPasswordEncoderInterface $userPasswordEncoder,
    EntityManagerInterface $entityManager,
    MailerInterface $mailer
) {
    $o = '';
    $Varmail = $_GET['email'];

    $user = new Utilisateur($o);
    $form = $this->createFormBuilder($user)
        ->add('password', PasswordType::class)
        ->getForm();
    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {
        $to = $Varmail;
        $sujet = 'Password Changed';
        $Message = "Bonjour $Varmail Votre email est changé !";
        $pass = $user->setPassword(
            $userPasswordEncoder->encodePassword(
                $user,
                $form->get('password')->getData()
            )
        );

        $URe->updateU($pass, $Varmail);

        $Mai = new MailerController();
        $Mai->sendEmail($mailer, $to, $sujet, $Message);
    }
    return $this->render('modifier_mdp/index.html.twig', [
        'form' => $form->createView(),
    ]);
}

How can i solve it , And Thanks

Originally created by @yassineMessaoud9 on GitHub (Apr 10, 2022). I am using a Symfony 4 project, and I want to change the user password, so I created a method in my repository and called it to the controller, but this error it diplay to me, `Binding entities to query parameters only allowed for entities that have an identifier. ` **Repository** ``` public function updateU($password,$email): ?Utilisateur { $dql = <<<DQL SELECT u FROM App\Entity\Utilisateur u WHERE u.email = :email AND u.password = :password DQL; return $this->getEntityManager()->createQuery($dql) ->setParameters(['email' => $email, 'password' => $password]) ->getSingleScalarResult(); ``` **Controller** ```/** * @Route("/Reset", name="Reset") * Method({"GET"}) */ public function New( Request $request, UtilisateurRepository $URe, UserPasswordEncoderInterface $userPasswordEncoder, EntityManagerInterface $entityManager, MailerInterface $mailer ) { $o = ''; $Varmail = $_GET['email']; $user = new Utilisateur($o); $form = $this->createFormBuilder($user) ->add('password', PasswordType::class) ->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $to = $Varmail; $sujet = 'Password Changed'; $Message = "Bonjour $Varmail Votre email est changé !"; $pass = $user->setPassword( $userPasswordEncoder->encodePassword( $user, $form->get('password')->getData() ) ); $URe->updateU($pass, $Varmail); $Mai = new MailerController(); $Mai->sendEmail($mailer, $to, $sujet, $Message); } return $this->render('modifier_mdp/index.html.twig', [ 'form' => $form->createView(), ]); } ``` How can i solve it , And Thanks
admin closed this issue 2026-01-22 15:42:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6959