简体   繁体   中英

Problem with routes in symfony annotations

I have a problem with routes in Symfony. I have them for annotations. I have created the controller with:

php bin/console make: controller DefaultController

Symfony's localhost/.../public/index.php page shows me the controller but if I put localhost/.../public/index.php/welcome it doesn't show me anything, I can't find the error

php bin/console debug:route
 -------------------------- -------- -------- ------ ----------------------------------- 
  Name                       Method   Scheme   Host   Path                               
 -------------------------- -------- -------- ------ ----------------------------------- 
  _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   
  autor                      ANY      ANY      ANY    /autor                             
  autor_list                 ANY      ANY      ANY    /autor/list                        
  autor_list_JSON            ANY      ANY      ANY    /autor/listJSON                    
  autor_new                  ANY      ANY      ANY    /autor/new                         
  home                       ANY      ANY      ANY    /welcome 

the /autor, /autor/list, autor/listJSON, autor/new path does not work either.

MY routes.yaml

#index:
#    path: /
#    controller: App\Controller\DefaultController::index

MY CONTROLLER

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends AbstractController
{
    /**
    * @Route("/default", name="default")
    */
    public function index(): Response
    {
    
        return $this->render('default/index.html.twig', [
            'controller_name' => 'DefaultController',
        ]);
    }
    /**
    * @Route("/welcome", name="home")
    */
    public function welcome()
    {
        $html = '<body>Hello world!</body>';
        return new Response($html);
    }
}

Deleting the vendor folder and generating it again with:

composer install --ignore-platform-reqs

Now it works correctly. Inside vendor there was an incorrect instance.

IMPORTANT , generate using --ignore-platform-reqs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM