在控制器中处理表单时请求错误

Request error when processing form in controller

我有一个正在创建它的表单:

private function createIntroForm()
{
    $form = $this->createForm('reporting_intro',null, array(
            'action' => $this->generateUrl('reporting_filter'),
            'method' => 'POST',
    ));

    $form->add('createreport', 'submit', array('label' => 'Create Report'));

    return $form;
}

并在控制器中渲染它:

$form = $this->createIntroForm();
return $this->render('ITWReportingBundle:Default:index.html.twig', array('form'=>$form->createView()));

我的路线是:

reporting:
    path:     /reporting
    defaults: { _controller: ITWReportingBundle:Default:index }

reporting_filter:
    path:     /filterreport
    defaults: { _controller: ITWReportingBundle:Default:filter }
    requirements: { _method: post }

我的控制器操作是:

public function indexAction()
{
    $form = $this->createIntroForm();
    return $this->render('ITWReportingBundle:Default:index.html.twig', array('form'=>$form->createView()));
}
public function filterAction(Request $request)
    {
        if ($request->getMethod() == 'POST') {
            $form = $this->createIntroForm();
            $form->handleRequest($request);
            $data = $form->getData();
            $module=$data->get("module");
            $mf=$this->createFilterForm($module);
            return $this->render('ITWReportingBundle:Default:filter.html.twig', array('form'=>$mf->createView()));
        }
        else
        {
            return $this->redirect($this->generateUrl('reporting'));
        }
    }

但是在我提交 reporting_intro 表格后,我得到:

Controller "ITW\ReportingBundle\Controller\DefaultController::filterAction()" requires that you provide a value for the "$request" argument (because there is no default value or because there is a non optional argument after this one).

这是我的php app/console debug:router

[router] Current routes
 Name                                Method      Scheme Host Path                                                  
 _assetic_fbfc370                    ANY         ANY    ANY  /css/fbfc370.css                                      
 _assetic_fbfc370_0                  ANY         ANY    ANY  /css/fbfc370_manageusers_1.css                        
 _assetic_3d5fe2c                    ANY         ANY    ANY  /images/3d5fe2c.png                                   
 _assetic_3d5fe2c_0                  ANY         ANY    ANY  /images/3d5fe2c_view_1.png                            
 _assetic_2a83733                    ANY         ANY    ANY  /images/2a83733.png                                   
 _assetic_2a83733_0                  ANY         ANY    ANY  /images/2a83733_edit_1.png                            
 _assetic_d37dbc5                    ANY         ANY    ANY  /images/d37dbc5.png                                   
 _assetic_d37dbc5_0                  ANY         ANY    ANY  /images/d37dbc5_delete_1.png                          
 _assetic_ce8b6b7                    ANY         ANY    ANY  /css/ce8b6b7.css                                      
 _assetic_ce8b6b7_0                  ANY         ANY    ANY  /css/ce8b6b7_theme_1.css                              
 _assetic_a925445                    ANY         ANY    ANY  /js/a925445.js                                        
 _assetic_a925445_0                  ANY         ANY    ANY  /js/a925445_jalali_1.js                               
 _assetic_a925445_1                  ANY         ANY    ANY  /js/a925445_calendar_2.js                             
 _assetic_a925445_2                  ANY         ANY    ANY  /js/a925445_calendar-setup_3.js                       
 _assetic_a925445_3                  ANY         ANY    ANY  /js/a925445_calendar-fa_4.js                          
 _assetic_c55a249                    ANY         ANY    ANY  /css/c55a249.css                                      
 _assetic_c55a249_0                  ANY         ANY    ANY  /css/c55a249_part_1_manageusers_1.css                 
 _assetic_c55a249_1                  ANY         ANY    ANY  /css/c55a249_part_1_style_2.css                       
 _assetic_4ef5586                    ANY         ANY    ANY  /images/4ef5586.png                                   
 _assetic_4ef5586_0                  ANY         ANY    ANY  /images/4ef5586_logo_1.png                            
 _assetic_ce68b4f                    ANY         ANY    ANY  /css/ce68b4f.css                                      
 _assetic_ce68b4f_0                  ANY         ANY    ANY  /css/ce68b4f_part_1_style_1.css                       
 _assetic_3d56d6a                    ANY         ANY    ANY  /js/3d56d6a.js                                        
 _assetic_3d56d6a_0                  ANY         ANY    ANY  /js/3d56d6a_part_1_scripts_1.js                       
 _assetic_4097f10                    ANY         ANY    ANY  /css/4097f10.css                                      
 _assetic_4097f10_0                  ANY         ANY    ANY  /css/4097f10_jquery.calendars.picker_1.css            
 _assetic_32f4d8b                    ANY         ANY    ANY  /js/32f4d8b.js                                        
 _assetic_32f4d8b_0                  ANY         ANY    ANY  /js/32f4d8b_jquery.plugin.min_1.js                    
 _assetic_32f4d8b_1                  ANY         ANY    ANY  /js/32f4d8b_jquery.calendars.all.min_2.js             
 _assetic_32f4d8b_2                  ANY         ANY    ANY  /js/32f4d8b_jquery.calendars.persian.min_3.js         
 _assetic_e84e667                    ANY         ANY    ANY  /js/e84e667.js                                        
 _assetic_e84e667_0                  ANY         ANY    ANY  /js/e84e667_jquery.calendars.persian-fa_1.js          
 _assetic_e84e667_1                  ANY         ANY    ANY  /js/e84e667_jquery.calendars.picker-fa_2.js           
 _assetic_e84e667_2                  ANY         ANY    ANY  /js/e84e667_jquery.calendars-fa_3.js                  
 _assetic_7a9d861                    ANY         ANY    ANY  /css/7a9d861.css                                      
 _assetic_7a9d861_0                  ANY         ANY    ANY  /css/7a9d861_style_1.css                              
 _assetic_ba7a5df                    ANY         ANY    ANY  /images/ba7a5df.png                                   
 _assetic_ba7a5df_0                  ANY         ANY    ANY  /images/ba7a5df_logout_1.png                          
 _assetic_d0fc915                    ANY         ANY    ANY  /css/d0fc915.css                                      
 _assetic_d0fc915_0                  ANY         ANY    ANY  /css/d0fc915_part_1_cssreset-min_1.css                
 _assetic_d0fc915_1                  ANY         ANY    ANY  /css/d0fc915_part_1_jquery.dataTables.min_2.css       
 _assetic_d0fc915_2                  ANY         ANY    ANY  /css/d0fc915_part_1_jquery.loadmask_3.css             
 _assetic_d0fc915_3                  ANY         ANY    ANY  /css/d0fc915_part_1_jquery.multiselect_4.css          
 _assetic_d0fc915_4                  ANY         ANY    ANY  /css/d0fc915_part_1_jquery.multiselect.filter_5.css   
 _assetic_d0fc915_5                  ANY         ANY    ANY  /css/d0fc915_part_1_shared_6.css                      
 _assetic_d0fc915_6                  ANY         ANY    ANY  /css/d0fc915_part_1_superfish_7.css                   
 _assetic_d0fc915_7                  ANY         ANY    ANY  /css/d0fc915_part_1_waiting_8.css                     
 _assetic_d0fc915_8                  ANY         ANY    ANY  /css/d0fc915_jquery-ui.min_2.css                      
 _assetic_d0fc915_9                  ANY         ANY    ANY  /css/d0fc915_jquery.fancybox_3.css                    
 _assetic_d0fc915_10                 ANY         ANY    ANY  /css/d0fc915_part_4_chosen.min_1.css                  
 _assetic_d0fc915_11                 ANY         ANY    ANY  /css/d0fc915_theme_5.css                              
 _assetic_be03f25                    ANY         ANY    ANY  /js/be03f25.js                                        
 _assetic_be03f25_0                  ANY         ANY    ANY  /js/be03f25_jquery_1.js                               
 _assetic_be03f25_1                  ANY         ANY    ANY  /js/be03f25_jquery-ui.min_2.js                        
 _assetic_be03f25_2                  ANY         ANY    ANY  /js/be03f25_jquery.fancybox.pack_3.js                 
 _assetic_be03f25_3                  ANY         ANY    ANY  /js/be03f25_jalali_4.js                               
 _assetic_be03f25_4                  ANY         ANY    ANY  /js/be03f25_calendar_5.js                             
 _assetic_be03f25_5                  ANY         ANY    ANY  /js/be03f25_calendar-setup_6.js                       
 _assetic_be03f25_6                  ANY         ANY    ANY  /js/be03f25_calendar-fa_7.js                          
 _assetic_be03f25_7                  ANY         ANY    ANY  /js/be03f25_jquery.dataTables.min_8.js                
 _assetic_be03f25_8                  ANY         ANY    ANY  /js/be03f25_jquery.waiting.min_9.js                   
 _assetic_be03f25_9                  ANY         ANY    ANY  /js/be03f25_part_10_chosen.jquery.min_1.js            
 _assetic_be03f25_10                 ANY         ANY    ANY  /js/be03f25_part_11_hoverIntent_1.js                  
 _assetic_be03f25_11                 ANY         ANY    ANY  /js/be03f25_part_11_jquery-migrate-1.2.1.min_2.js     
 _assetic_be03f25_12                 ANY         ANY    ANY  /js/be03f25_part_11_jquery.loadmask.min_5.js          
 _assetic_be03f25_13                 ANY         ANY    ANY  /js/be03f25_part_11_jquery.mousewheel-3.0.6.pack_6.js 
 _assetic_be03f25_14                 ANY         ANY    ANY  /js/be03f25_part_11_jquery.multiselect.filter_7.js    
 _assetic_be03f25_15                 ANY         ANY    ANY  /js/be03f25_part_11_jquery.multiselect_8.js           
 _assetic_be03f25_16                 ANY         ANY    ANY  /js/be03f25_part_11_jquery.multiselect.min_9.js       
 _assetic_be03f25_17                 ANY         ANY    ANY  /js/be03f25_part_11_shared_11.js                      
 _assetic_be03f25_18                 ANY         ANY    ANY  /js/be03f25_part_11_superfish.min_12.js               
 _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_purge                     ANY         ANY    ANY  /_profiler/purge                                      
 _profiler_info                      ANY         ANY    ANY  /_profiler/info/{about}                               
 _profiler_phpinfo                   ANY         ANY    ANY  /_profiler/phpinfo                                    
 _profiler_search_results            ANY         ANY    ANY  /_profiler/{token}/search/results                     
 _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                      
 _configurator_home                  ANY         ANY    ANY  /_configurator/                                       
 _configurator_step                  ANY         ANY    ANY  /_configurator/step/{index}                           
 _configurator_final                 ANY         ANY    ANY  /_configurator/final                                  
 reporting                           ANY         ANY    ANY  /reporting                                            
 reporting_filter                    POST        ANY    ANY  /filterreport                                         
 contract                            ANY         ANY    ANY  /contract/                                            
 contract_show                       ANY         ANY    ANY  /contract/{id}/show                                   
 contract_new                        ANY         ANY    ANY  /contract/new                                         
 contract_create                     POST        ANY    ANY  /contract/create                                      
 contract_edit                       ANY         ANY    ANY  /contract/{id}/edit                                   
 contract_update                     POST|PUT    ANY    ANY  /contract/{id}/update                                 
 contract_delete                     POST        ANY    ANY  /contract/delete                                      
 person                              ANY         ANY    ANY  /person/                                              
 person_show                         ANY         ANY    ANY  /person/{id}/show                                     
 person_new                          ANY         ANY    ANY  /person/new                                           
 person_create                       POST        ANY    ANY  /person/create                                        
 person_edit                         ANY         ANY    ANY  /person/{id}/edit                                     
 person_update                       POST|PUT    ANY    ANY  /person/{id}/update                                   
 person_delete                       POST|DELETE ANY    ANY  /person/{id}/delete                                   
 contact                             ANY         ANY    ANY  /contact/                                             
 contact_show                        ANY         ANY    ANY  /contact/{id}/show                                    
 contact_new                         ANY         ANY    ANY  /contact/new                                          
 contact_create                      POST        ANY    ANY  /contact/create                                       
 contact_edit                        ANY         ANY    ANY  /contact/{id}/edit                                    
 contact_update                      POST|PUT    ANY    ANY  /contact/{id}/update                                  
 contact_delete                      POST        ANY    ANY  /contact/delete                                       
 contact_getpersonincontact          POST        ANY    ANY  /contact/ajaxGetPersonsInContact                      
 contact_getcontactsingroup          POST        ANY    ANY  /contact/ajaxContactInGroup                           
 itw_contact_homepage                ANY         ANY    ANY  /hello/{name}                                         
 usergroups                          ANY         ANY    ANY  /usergroups/                                          
 usergroups_show                     ANY         ANY    ANY  /usergroups/{id}/show                                 
 usergroups_new                      ANY         ANY    ANY  /usergroups/new                                       
 usergroups_create                   POST        ANY    ANY  /usergroups/create                                    
 usergroups_edit                     ANY         ANY    ANY  /usergroups/{id}/edit                                 
 usergroups_update                   POST|PUT    ANY    ANY  /usergroups/{id}/update                               
 usergroups_delete                   POST        ANY    ANY  /usergroups/delete                                    
 usergroups_get_perms                POST        ANY    ANY  /usergroups/getpermlist                               
 login                               ANY         ANY    ANY  /login                                                
 login_check                         ANY         ANY    ANY  /login_check                                          
 logout                              ANY         ANY    ANY  /logout                                               
 users_list                          ANY         ANY    ANY  /listUsers                                            
 user_new                            ANY         ANY    ANY  /addUser                                              
 user_create                         POST        ANY    ANY  /addUser                                              
 user_update                         POST        ANY    ANY  /editUser/{id}                                        
 user_edit                           ANY         ANY    ANY  /editUser/{id}                                        
 user_delete                         POST        ANY    ANY  /deleteUser                                           
 user_show                           ANY         ANY    ANY  /showUser/{id}                                        
 updateProfile                       POST        ANY    ANY  /profile                                              
 profile                             ANY         ANY    ANY  /profile                                              
 basicsetting                        ANY         ANY    ANY  /basicsetting/                                        
 basicsetting_update                 POST|PUT    ANY    ANY  /basicsetting/update                                  
 homepage                            ANY         ANY    ANY  /                                                     
 notifier_update                     POST        ANY    ANY  /getNotifies                                          
 contact_dev                         ANY         ANY    ANY  /contact_developers                                   
 _uploader_upload_pmattchments       POST        ANY    ANY  /_uploader/pmattchments/upload                        
 _uploader_upload_announceattchments POST        ANY    ANY  /_uploader/announceattchments/upload                  
 _uploader_upload_bidreqattchments   POST        ANY    ANY  /_uploader/bidreqattchments/upload                    

问题是什么?

您需要使用

在您的控制器中导入 Request class
use Symfony\Component\HttpFoundation\Request;