找不到"GET/home"的路线

Nem*_*mus 1 symfony

我正在使用Symfony 3.4.3.这是我的路由 app/config/routing.yml:

blog:
    resource: "@BlogBundle/Controller/"
    type: annotation
Run Code Online (Sandbox Code Playgroud)

这是我的控制器 BlogBundle/Controller/DefaultController.php

<?php

namespace BlogBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

/**
 * @Route("/home", name="home_route")
 */
class DefaultController extends Controller
{
    public function indexAction()
    {
        return $this->render('BlogBundle:Default:index.html.twig');
    }
}
Run Code Online (Sandbox Code Playgroud)

当我去http:// localhost:8000/home地址时,我收到此错误:No route found for "GET /home"

那么,我在这里做错了什么?

Mou*_*adK 8

您添加以在操作上设置路径注释

<?php

namespace BlogBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    /**
     * @Route("/home", name="home_route")
     */
    public function indexAction()
    {
        return $this->render('BlogBundle:Default:index.html.twig');
    }
}
Run Code Online (Sandbox Code Playgroud)

如果在类上使用注释,则为所有操作添加前缀