为了账号安全,请及时绑定邮箱和手机立即绑定

Annoation Route 在 symfony 4.2.8 中不起作用

Annoation Route 在 symfony 4.2.8 中不起作用

PHP
紫衣仙女 2021-06-21 15:38:28
我使用 symfony 4 来创建页面。像这样创建 ArticleController:namespace App\Controller;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\Routing\Annotation\Route;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;use Symfony\Bundle\FrameworkBundle\Controller\Controller;class ArticleController extends Controller{    public function index()    {        /**         * @Route("/")         * @Method({"GET"})        */        return new Response(            '<html><body>Hello !!!</body></html>'        );    }}我使用 composer 安装注释,这是我的composer.json文件:{    "type": "project",    "license": "proprietary",    "require": {        "php": "^7.1.3",        "ext-ctype": "*",        "ext-iconv": "*",        "sensio/framework-extra-bundle": "^5.3",        "symfony/console": "4.2.*",        "symfony/dotenv": "4.2.*",        "symfony/flex": "^1.1",        "symfony/framework-bundle": "4.2.*",        "symfony/twig-bundle": "4.2.*",        "symfony/yaml": "4.2.*"    },    "config": {        "preferred-install": {            "*": "dist"        },        "sort-packages": true    },    "autoload": {        "psr-4": {            "App\\": "src/"        }    },    "autoload-dev": {        "psr-4": {            "App\\Tests\\": "tests/"        }    },    "replace": {        "paragonie/random_compat": "2.*",        "symfony/polyfill-ctype": "*",        "symfony/polyfill-iconv": "*",        "symfony/polyfill-php71": "*",        "symfony/polyfill-php70": "*",        "symfony/polyfill-php56": "*"    },    "scripts": {        "auto-scripts": {            "cache:clear": "symfony-cmd",            "assets:install %PUBLIC_DIR%": "symfony-cmd"        },        "post-install-cmd": [            "@auto-scripts"        ],        "post-update-cmd": [            "@auto-scripts"        ]    },    "conflict": {        "symfony/symfony": "*"    },现在,当我查看浏览器 url 时:smfony.local我看到了 symfony 欢迎页面。我使用routes.yaml文件检查路线,我的路线工作正常且真实(显示您好!!!消息)但注释路线对我不起作用。我该如何解决这个问题?!
查看完整描述

1 回答

?
回首忆惘然

TA贡献1847条经验 获得超11个赞

我认为您需要在路线之前移动注释:


/**

* @Route("/", name="index")

*/

public function index()

{


    return new Response(

        '<html><body>Hello !!!</body></html>'

    );


}

还要确保添加注释 composer require annotations


查看完整回答
反对 回复 2021-06-25
  • 1 回答
  • 0 关注
  • 132 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号