简体   繁体   中英

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

I'm trying to get started with Symfony2 and I'm getting stuck on the "create your first page" tutorial : http://symfony.com/doc/current/book/page_creation.html

I created the controller file (copy-pasted from tutorial) as E:\\Web\\project\\src\\AppBundle\\Controller\\LuckyController.php :

<?php
// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

class LuckyController
{
    /**
     * @Route("/lucky/number")
     */
    public function numberAction()
    {
        $number = rand(0, 100);

        return new Response(
            '<html><body>Lucky number: '.$number.'</body></html>'
        );
    }
}

I didn't make any change to any other file.

When I go to the URL 127.0.0.1/project/web/app_dev.php/lucky/controller (127.0.0.1 is the virtual host for E:\\Web) I keep getting the error " No route found for "GET /lucky/controller" ".

404 Not Found - NotFoundHttpException
1 linked Exception:
[2/2] NotFoundHttpException: No route found for "GET /lucky/controller/"
[1/2] ResourceNotFoundException:

If I remove the "/web" from the URL, 127.0.0.1/project/app_dev.php/lucky/controller , I get a 404 error.

I'm pretty sure the error comes from the folder structure since the files are unmodified. Similar issue was reported here but none of these suggestions solved my error.

Just figured out that the URL should be 127.0.0.1/project/web/app_dev.php/lucky/number (and not controller ). Problem solved.

Be careful, your route is /lucky/number not /lucky/controller .

So, you have to try with 127.0.0.1/project/web/app_dev.php/lucky/number

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