页面重新加载后,Doctrine 保留旧记录

时间:2021-07-09 18:42:54

标签: php symfony doctrine

我真的很挣扎,所以我希望有人可以帮助我...

我在我的 Symfony 5.3 应用程序中有一个简单的设置:我创建了一个基本的 Doctrine 实体 (User)、表单类型 (UserFormType) 和表单模型类 (UserFormModel) 来管理用户帐户。当我提交表单时,一切都按预期工作——新数据会保留到数据库中。奇怪的是,如果我刷新页面或访问站点的完全不同的部分(如帮助页面),Doctrine 会执行一个更新查询,将先前的记录恢复到数据库中。用于更新用户的唯一逻辑位于我在下面分享的一段代码中。我完全不明白为什么 Doctrine 运行更新查询来恢复以前的记录,即使访问我网站的一个完全不同的页面......

        $form = $this->createForm(UserType::class, $model);
        $form->handleRequest($this->r);

        if ($form->isSubmitted() && $form->isValid()) {
            $model = $form->getData();
            $obj->build($model);

            $this->em->persist($obj);
            $this->em->flush();

            return $this->redirectToRoute('admin_user');
        }

调试:路由器输出

  _preview_error                                 ANY        ANY      ANY    /_error/{code}.{_format}                             
  _wdt                                           ANY        ANY      ANY    /_wdt/{token}                                        
  _profiler_home                                 ANY        ANY      ANY    /_profiler/                                          
  _profiler_search                               ANY        ANY      ANY    /_profiler/search                                    
  _profiler_search_bar                           ANY        ANY      ANY    /_profiler/search_bar                                
  _profiler_phpinfo                              ANY        ANY      ANY    /_profiler/phpinfo                                   
  _profiler_search_results                       ANY        ANY      ANY    /_profiler/{token}/search/results                    
  _profiler_open_file                            ANY        ANY      ANY    /_profiler/open                                      
  _profiler                                      ANY        ANY      ANY    /_profiler/{token}                                   
  _profiler_router                               ANY        ANY      ANY    /_profiler/{token}/router                            
  _profiler_exception                            ANY        ANY      ANY    /_profiler/{token}/exception                         
  _profiler_exception_css                        ANY        ANY      ANY    /_profiler/{token}/exception.css                     
  admin                                          ANY        ANY      ANY    /admin                                               
  admin_user                                     ANY        ANY      ANY    /admin/user                                          
  admin_user_crud                                ANY        ANY      ANY    /admin/user/{action}/{id}                            
  admin_organization                             ANY        ANY      ANY    /admin/organization                                  
  admin_organization_crud                        ANY        ANY      ANY    /admin/organization/{action}/{id}                    
  admin_plan                                     ANY        ANY      ANY    /admin/plan                                          
  admin_plan_crud                                ANY        ANY      ANY    /admin/plan/{action}/{id}                            
  admin_subject                                  ANY        ANY      ANY    /admin/subject                                       
  admin_subject_crud                             ANY        ANY      ANY    /admin/subject/{action}/{id}                         
  component_home                                 ANY        ANY      ANY    /{institution}/{component}/home                      
  component_search                               ANY        ANY      ANY    /{institution}/{component}/search/{type}             
  component_request                              ANY        ANY      ANY    /{institution}/{component}/request/{type}/{id}       
  component_summary                              ANY        ANY      ANY    /{institution}/{component}/summary/{type}/{id}       
  help                                           ANY        ANY      ANY    /help                                                
  registrar_home                                 ANY        ANY      ANY    /{institution}/registrar/home                        
  search                                         ANY        ANY      ANY    /search

1 个答案:

答案 0 :(得分:0)

我太蠢了……我想通了是怎么回事。我刚刚意识到我已经向我的 UserProvider 添加了逻辑,从我公司的目录中提取数据并在每次页面刷新时更新用户的信息。