Thanks to visit codestin.com
Credit goes to github.com

Skip to content

name_prefix will duplicate all my resource routes #29079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
devnix opened this issue Nov 4, 2018 · 4 comments
Closed

name_prefix will duplicate all my resource routes #29079

devnix opened this issue Nov 4, 2018 · 4 comments

Comments

@devnix
Copy link

devnix commented Nov 4, 2018

I think it's a bug related with the feature #19612

I have a route group for an admin section, and I want to prefix the URL and name of each route inside the App\Controller\Admin namespace.

If I go only for the route prefix it works without any problem

# config/routes.yaml
admin:
  prefix: /admin
  resource: ../src/Controller/Admin
  type: annotation

The router debug gives me the following output:

 -------------------------- ---------- -------- ------ ----------------------------------- 
  Name                       Method     Scheme   Host   Path                               
 -------------------------- ---------- -------- ------ ----------------------------------- 
  _twig_error_test           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   
  index                      ANY        ANY      ANY    /admin/                            
  login                      ANY        ANY      ANY    /admin/login                       
  user_index                 GET        ANY      ANY    /admin/user                        
  user_new                   GET|POST   ANY      ANY    /admin/user/new                    
  user_show                  GET        ANY      ANY    /admin/user/{id}                   
  user_edit                  GET|POST   ANY      ANY    /admin/user/{id}/edit              
  user_delete                DELETE     ANY      ANY    /admin/user/{id}                   
  admin_logout               ANY        ANY      ANY    /admin/logout                      
 -------------------------- ---------- -------- ------ ----------------------------------- 

The problem comes when I add the name_prefix route:

# config/routes.yaml
admin:
  name_prefix: admin_
  prefix: /admin
  resource: ../src/Controller/Admin
  type: annotation

The router debug gives the following output, and I can verify that the URLs are duplicated:

 -------------------------- ---------- -------- ------ ----------------------------------- 
  Name                       Method     Scheme   Host   Path                               
 -------------------------- ---------- -------- ------ ----------------------------------- 
  index                      ANY        ANY      ANY    /                                  
  login                      ANY        ANY      ANY    /login                             
  user_index                 GET        ANY      ANY    /user                              
  user_new                   GET|POST   ANY      ANY    /user/new                          
  user_show                  GET        ANY      ANY    /user/{id}                         
  user_edit                  GET|POST   ANY      ANY    /user/{id}/edit                    
  user_delete                DELETE     ANY      ANY    /user/{id}                         
  _twig_error_test           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_index                ANY        ANY      ANY    /admin/                            
  admin_login                ANY        ANY      ANY    /admin/login                       
  admin_user_index           GET        ANY      ANY    /admin/user                        
  admin_user_new             GET|POST   ANY      ANY    /admin/user/new                    
  admin_user_show            GET        ANY      ANY    /admin/user/{id}                   
  admin_user_edit            GET|POST   ANY      ANY    /admin/user/{id}/edit              
  admin_user_delete          DELETE     ANY      ANY    /admin/user/{id}                   
  admin_logout               ANY        ANY      ANY    /admin/logout                      
 -------------------------- ---------- -------- ------ ----------------------------------- 

Originally posted by @devnix in #19612 (comment)

@xabbuh
Copy link
Member

xabbuh commented Nov 5, 2018

Are you sure that there isn't simply another config file that loads the routes without the prefix? Could you create a small example application that allows to reproduce?

@Tobion
Copy link
Contributor

Tobion commented Nov 5, 2018

You probably have this config as well https://github.com/symfony/recipes/blob/5b3ce909504b9366405820c49bc9f0e13ac4be54/doctrine/annotations/1.0/config/routes/annotations.yaml#L1-L3

This adds the routes from all annotations. Then you also import them under a prefix, which creates the duplicate routes. So you need to exclude the controller from the auto discovery.

@Th3Mouk
Copy link
Contributor

Th3Mouk commented Nov 7, 2018

Hello

I had a similar issue with a fresh 4.1 install:

# routes.yaml
billing:
    name_prefix: billing_
    prefix: /billing
    resource: routes/billing.yaml

# billing.yaml
search:
    path: /search
    controller: App\Controller\BillingController::search
    methods: [POST, OPTIONS]
 ---------------- -------------- -------- ------ -----------------
  Name             Method         Scheme   Host   Path
 ---------------- -------------- -------- ------ -----------------
  search           POST|OPTIONS   ANY      ANY    /search
  billing_search   POST|OPTIONS   ANY      ANY    /billing/search
 ---------------- -------------- -------- ------ -----------------

I resolved the problem commenting some lines in Kernel.php

protected function configureRoutes(RouteCollectionBuilder $routes)
{
    $confDir = $this->getProjectDir().'/config';

//    $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
//    $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
    $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
}

I have a question about the annotations.yaml file, is there a way for the recipe not to install this file?
Because I don't want to use annotation in my project.

Thanks for helping

@xabbuh
Copy link
Member

xabbuh commented Nov 8, 2018

I have a question about the annotations.yaml file, is there a way for the recipe not to install this file?
Because I don't want to use annotation in my project.

You can just remove it from your project.

@xabbuh xabbuh closed this as completed Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants