Symfony4注释布线不起作用 [英] Symfony4 Annotation routing does not work

查看:20
本文介绍了Symfony4注释布线不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习symfony。我完全遵循this official tutorial。使用config/routes.yaml但使用annotations

时,路由工作正常
namespace AppController;

use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentAnnotationRoute;

class LuckyController
{

    /**
     *  @Route("/lucky/number")
     */
    public function number(){

        $number = mt_rand(0, 100);

        return new Response(
            '<html><body><h1>MyLucky Number: ' . $number . '</h1></body></html>'
        );
    }
}

我收到此错误:

    Exception thrown when handling an exception
(SymfonyComponentConfigExceptionFileLoaderLoadException: [Semantical Error]
 The annotation "@SymfonyComponentAnnotationRoute" in method 
AppControllerLuckyController::number() does not exist, or could not be auto-loaded
 in C:wampvhostsmysymfony4config/routes../../src/Controller/ (which is
 being imported from "C:wampvhostsmysymfony4config/routes/annotations.yaml"). Make sure
 annotations are installed and enabled.)

推荐答案

我发现了我的错误。我使用了错误的命名空间进行路由。

use SymfonyComponentAnnotationRoute;

应该是:

use SymfonyComponentRoutingAnnotationRoute;

编辑: 我想删除此问题,但系统不允许。

这篇关于Symfony4注释布线不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆