尝试遵循 Symfony 3.1 书:
这是我的 Controller
<?php
namespace AppBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class LuckyController
{
/**
* @Route("/lucky/number")
*/
public function numberAction() {
$num = rand(0,100);
return new Response("number is ". $num);
}
}
该书转到以下网址:http://localhost:8000/lucky/number
查看响应。然而,对我来说,这以 404
The requested resource /lucky/number was not found on this server.
结束。 .从阅读其他一些类似的问题来看,路由似乎可以通过注释来完成。这里的代码有什么问题?
编辑:关于网络服务器:我正在从 web/目录运行内置的 php 服务器。即
php -S localhost:8000
.也跑了 php bin/console server:run
- 发回 No route found for "GET /lucky/number
最佳答案
这里还有另一个可能的问题,那就是缓存的存在。如果您正在学习本教程,您可能已经看过第一页,因此 Symfony 缓存了类和路由。
为了确保 Symfony 接受这些更改,请确保清除缓存(使用正确的环境参数):
php bin/console cache:clear --no-warmup -e prod
关于routing - 找不到 Symfony 3 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38111861/