You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Symfony 6.0属性路由加载失败问题求助(PHP 8.0.30)

解决Symfony 6.0属性路由加载失败问题

问题原因

Symfony 6.0虽支持PHP属性定义路由,但通过目录批量加载属性路由时,type: attribute是Symfony 6.2及以上版本才新增的特性。你当前使用的6.0版本不识别该配置类型,因此触发报错。

解决方案

将路由配置文件中的type: attribute替换为type: annotation——Symfony 6.0的AnnotationLoader组件同时兼容PHP属性和注解两种路由定义方式。

修改config/routes/attributes.yaml内容如下:

controllers:
  resource: ../../src/Controller/
  type: annotation

kernel:
  resource: ../../src/Kernel.php
  type: annotation

验证操作

执行以下命令确认路由是否加载成功:

php bin/console debug:router

此时product_list路由应出现在输出列表中。

额外检查

  1. 确保Symfony核心组件版本统一为6.0.x,避免版本混合引发兼容问题:
    composer show symfony/framework-bundle
    
  2. 确认config/packages/framework.yaml中路由注解支持已开启(6.0默认开启):
    framework:
        router:
            annotate: true
    

内容的提问来源于stack exchange,提问作者spider5414

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 14:33:34