【发布时间】:2022-08-24 05:21:32
【问题描述】:
我刚刚安装了一个新的 Symfony 6 框架,并使用php bin/console make:controller 创建了IndexController.php,结果如下:
#[Route(\'/index\', name: \'app_index\')]
public function index(): Response
{
return $this->render(\'index/index.html.twig\', [
\'controller_name\' => \'IndexController\',
]);
}
但是该路由不起作用并导致 404 错误。我执行了路由调试器,以下输出确认我的路由已被框架识别:
php bin/console debug:router
-------------------------- -------- -------- ------ -----------------------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
app_index ANY ANY ANY /index
-------------------------- -------- -------- ------ -----------------------------------
-
为什么我的路线不起作用?
-
如何配置 Symfony 以生成以下格式的路由注释:
/** * @Route(\"/index\", name=\"app_index\") */