Symfony2: No route found for “GET /lucky/number”

后端 未结 11 1296
北荒
北荒 2021-02-18 14:17

I start the tutorial (as newbie) and everythings works fine till:

http://symfony.com/doc/current/book/page_creation.html#creating-a-page-route-and-controller at step

11条回答
  •  忘掉有多难
    2021-02-18 15:13

    You actually don't extend Symfony Controller class. It should be class LuckyController extends Controller

    // src/AppBundle/Controller/LuckyController.php 
    namespace AppBundle\Controller; 
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
    use Symfony\Component\HttpFoundation\Response;
    
    class LuckyController extends Controller {
    
         /** 
          * @Route("/lucky/number") 
          */ 
         public function numberAction() { 
             $number = rand(0, 100); 
             return new Response('Lucky number: '.$number.'');
         }
    
    }
    

    EDIT: after all, the problem in this question was not in extending controller, so ignore my answer.

提交回复
热议问题