【发布时间】:2021-01-14 18:26:26
【问题描述】:
我最近重新打开了一个相当大的 Symfony 4.4 项目。使用 PhpStorm 2020.3 浏览代码,添加一些新功能和代码清理。
我访问了几个控制器,但在 PhpStorm 中出现“缺少路由”错误。但是,当我运行php bin/console debug:router 时,路线确实存在。
是否有我尚未清除的缓存导致 PhpStorm 重新扫描路由?
输出来自:php bin/console debug:router
admin_deviceprofile_index 获取任何 /admin/deviceprofile/
admin_deviceprofile_show 获取任何 /admin/deviceprofile/{deviceprofile_id}/show
admin_deviceprofile_create GET|POST ANY ANY /admin/deviceprofile/create
admin_deviceprofile_edit GET|POST ANY ANY /admin/deviceprofile/{deviceprofile_id}/edit
admin_deviceprofile_delete 删除任何 /admin/deviceprofile/{deviceprofile_id}/delete
我的控制器的 sn-p ...
/**
* @Route("/admin/deviceprofile",
* name="admin_deviceprofile_")
*/
class DeviceProfileController extends AbstractController
{
/**
* Lists all Device Profiles.
* @Route("/",
* name="index",
* methods={"GET"})
* @param Request $request
* @return Response
*/
public function index(Request $request): Response
{ ... }
/**
* Creates a new Device Profile entity.
* @Route("/create",
* name="create",
* methods={"GET", "POST"})
* @param Request $request
* @return Response
*/
public function create(Request $request): Response
{
$profile = new DeviceProfile();
$formProfile = $this->createForm(DeviceProfileType::class, $profile);
$formProfile->handleRequest($request);
if ($formProfile->isSubmitted() && $formProfile->isValid()) {
...
return $this->redirectToRoute('admin_deviceprofile_index');
}
return $this->render(...);
}
}
PhpStorm 声称 'admin_deviceprofile_index' 丢失。然而,事实并非如此。此外,在其他地方也使用了控制器路由的相同模式,但这些路由很好,问题只出现在几个控制器中。
另外,通过调试这个“问题”,我将控制器路由部分移动到函数本身,PhpStorm 仍然没有正确看到路由。
我也跑了php bin/console cache:clear 并完成了 PhpStorm: File > Invalidate Caches / Restart 无济于事。
我可以尝试解决这个问题吗?我讨厌在代码检查中看到“错误”。
【问题讨论】:
-
Symfony Support plugin 提供了此类 Symfony 特定功能。也许检查他们的Issue Tracker。附言我不是 Symfony 用户,所以不确定到底需要什么 .. 但由于该路径是通过
@Route声明的——你是否安装了 PHP Annotations 插件?它就是处理此类注释的那个(也许这里也需要它)。