我使用的是Symfony 3.4.3。
这是我的路由
app/config/routing.yml
:
blog:
resource: "@BlogBundle/Controller/"
type: annotation
这是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');
}
}
当我转到http://localhost:8000/home地址时,我收到此错误:No route found for "GET /home"
那么,我在这里做错了什么?
答案 0 :(得分: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');
}
}
如果您在课堂上使用注释,将为所有操作添加前缀