关于文档https://symfony.com/doc/current/controller.html#streaming-file-responses我在我的控制器中构建了一个简单的函数,所以当有人点击链接<a href = "/download/">下载Excel文件</ a>时,他就可以下载该文件了 .

/**
* @Route("/download/", name="download")
*/
public function download()
{
    // send the file contents and force the browser to download it
    return $this->file($this->getParameter('xls_directory') . 'hello_world.xls');
}

但是当我使用这个链接时,Symfony告诉我没有页面 . 当我在Command中运行“php bin / console debug:router”时,没有列出“/ download /”页面 . 即使我清除缓存后 . 我不明白这一点 . (路径和文件是正确的......)非常感谢 .