symfony 路由前缀不起作用

symfont route prefix not working

我用 kunstmaan/adminlist-bundle 生成了 2 个管理员列表,发现无法识别 routing.yml 中指定的前缀。

MyBundle/Resource/config/routing.yml

appbundle_importerror_admin_list:
    resource: @AppBundle/Controller/ImportErrorAdminListController.php
    type:     annotation
    prefix:   /admin/importerror

appbundle_filetosync_admin_list:
    resource: @AppBundle/Controller/FileToSyncAdminListController.php
    type:     annotation
    prefix:   /admin/filetosync/

但是当我 运行 bin/console debug:router 我得到

homepage                                ANY        ANY      ANY    /                                  
appbundle_admin_filetosync              ANY        ANY      ANY    /                                  
appbundle_admin_filetosync_add          GET|POST   ANY      ANY    /add                               
appbundle_admin_filetosync_edit         GET|POST   ANY      ANY    /{id}                              
appbundle_admin_filetosync_view         GET        ANY      ANY    /{id}                              
appbundle_admin_filetosync_delete       GET|POST   ANY      ANY    /{id}/delete                       
appbundle_admin_filetosync_export       GET|POST   ANY      ANY    /export.{_format}                  
appbundle_admin_filetosync_move_up      GET        ANY      ANY    /{id}/move-up                      
appbundle_admin_filetosync_move_down    GET        ANY      ANY    /{id}/move-down                    
appbundle_admin_importerror             ANY        ANY      ANY    /                                  
appbundle_admin_importerror_add         GET|POST   ANY      ANY    /add                               
appbundle_admin_importerror_edit        GET|POST   ANY      ANY    /{id}                              
appbundle_admin_importerror_view        GET        ANY      ANY    /{id}                              
appbundle_admin_importerror_delete      GET|POST   ANY      ANY    /{id}/delete                       
appbundle_admin_importerror_export      GET|POST   ANY      ANY    /export.{_format}                  
appbundle_admin_importerror_move_up     GET        ANY      ANY    /{id}/move-up                      
appbundle_admin_importerror_move_down   GET        ANY      ANY    /{id}/move-down

如何让这些路由应用前缀?

kunstmaan bundle 在 AppBundle/Resources/routing.yml 中创建这些前缀,但它们不起作用,因为路由是在注释中完成的,不能在 yaml 和注释之间混合。

所以我找到的解决方案是将它们从 routing.yml

中删除
appbundle_importerror_admin_list:
    resource: @AppBundle/Controller/ImportErrorAdminListController.php
    type:     annotation

appbundle_filetosync_admin_list:
    resource: @AppBundle/Controller/FileToSyncAdminListController.php
    type:     annotation

并将它们添加到控制器 类:

/**
 * The admin list controller for ImportError
 *
 * @Route("/admin/importerror")
 */

class ImportErrorAdminListController extends AdminListController