使用 symfony 更新控制器中的数据库

update the database in my controller with symfony

如何在 symfony 控制器中更新 我现在从查询参数中获得了用户 ID 和名称,如果可以很好地检索到此信息,则将 'etat' 的值更改为 1,我尝试过,但它不起作用 "'

/**
        * @Route("/acceptation", name="acceptation")
        */

        public function acceptation(Request $request, EntityManagerInterface $em, ValidatorInterface $validator):Response
        {
            $idU = $request->get('idUtilisateur');
            $nom= $request->get('nomTontine');

            $participant = $this->getDoctrine()->getRepository(Participants::class)->findOneBy(['idUtilisateur'=> $idU , 'nomTontine'=> $nom]) ;            
            if( $participant)
            {
                
                $part= new Participants();
                $part->setEtat(1);
                $em -> persist($participant);
                    $em->flush();
                    
            }
            return $this->render('sunutontine/acceptation.html.twig' ,[
                'controller_name' => 'SunuController',
                ]);
    }

'"

您将更新现有实体,因此不要实例化新对象。

坚持,编辑时也不是必须的

if( $participant)
{
              
   $participant->setEtat(1);
  
   $em->flush();
                
}