路由在 Symfony 3.2 中不起作用
Routing is not work in Symfony 3.2
我使用 docs 中的示例。
这是
routing.yml:
app:
resource: '@AppBundle/Controller/'
type: annotation
blog_list:
path: /blog/{page}
defaults: { _controller: AppBundle:Blog:list , page: 1}
requirements:
page: '\d+'
还有这个控制器:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class BlogController extends Controller
{
/**
* @Route("/blog/{page}", name="blog_list", requirements={"page": "\d+"})
*/
public function listAction($page = 1)
{
$number = mt_rand(0, 100);
return $this->render('lucky/number.html.twig',['number'=>$number]);
}
}
我看到错误:
The routing file "/var/www/pars/app/config/routing.yml" contains unsupported keys for "app": "blog_list". Expected one of: "resource", "type", "prefix", "path", "host", "schemes", "methods", "defaults", "requirements", "options", "condition" in /var/www/pars/app/config/routing.yml (which is being imported from "/var/www/pars/app/config/routing_dev.yml").
为什么?
似乎只是一个缩进问题:新路由应该在低层:
app:
resource: '@AppBundle/Controller/'
type: annotation
blog_list:
path: /blog/{page}
defaults: { _controller: AppBundle:Blog:list , page: 1}
requirements:
page: '\d+'
希望对您有所帮助
我使用 docs 中的示例。 这是 routing.yml:
app:
resource: '@AppBundle/Controller/'
type: annotation
blog_list:
path: /blog/{page}
defaults: { _controller: AppBundle:Blog:list , page: 1}
requirements:
page: '\d+'
还有这个控制器:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class BlogController extends Controller
{
/**
* @Route("/blog/{page}", name="blog_list", requirements={"page": "\d+"})
*/
public function listAction($page = 1)
{
$number = mt_rand(0, 100);
return $this->render('lucky/number.html.twig',['number'=>$number]);
}
}
我看到错误:
The routing file "/var/www/pars/app/config/routing.yml" contains unsupported keys for "app": "blog_list". Expected one of: "resource", "type", "prefix", "path", "host", "schemes", "methods", "defaults", "requirements", "options", "condition" in /var/www/pars/app/config/routing.yml (which is being imported from "/var/www/pars/app/config/routing_dev.yml").
为什么?
似乎只是一个缩进问题:新路由应该在低层:
app:
resource: '@AppBundle/Controller/'
type: annotation
blog_list:
path: /blog/{page}
defaults: { _controller: AppBundle:Blog:list , page: 1}
requirements:
page: '\d+'
希望对您有所帮助