首页 > 解决方案 > _symfony 4 中的本地管理

问题描述

我尝试在我的路线中设置变量 {_local} ...这是控制器


    /*
    * @Route("/{_locale}" , name="home" , requirements={"_locale": "en|fr"})
    */
    public function generalHome($_locale)
    {
      dump($_locale) ;

      return $this->render('customer/home/home.html.twig');
    }

/en 当我在浏览器中输入网址时,

Symfony 返回错误:

No route found for "GET /en"

PS:我没有修改任何其他文件

标签: symfonysymfony4

解决方案


我可能是错的,但看起来你的路线没有找到。这可能是由于您的 routes.yml 未导入注释引起的:

# config/routes/annotations.yaml
controllers:
    resource: '../../src/Controller/'
    type: annotation

有关路由的更多信息


推荐阅读