【发布时间】:2023-03-18 08:52:01
【问题描述】:
我刚开始学习 Symfony。我正在关注this official tutorial。使用config/routes.yaml 完成路由工作正常,但使用annotations:
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Annotation\Route;
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
(Symfony\Component\Config\Exception\FileLoaderLoadException: [Semantical Error]
The annotation "@Symfony\Component\Annotation\Route" in method
App\Controller\LuckyController::number() does not exist, or could not be auto-loaded
in C:\wamp\vhosts\mysymfony4\config/routes\../../src/Controller/ (which is
being imported from "C:\wamp\vhosts\mysymfony4\config/routes/annotations.yaml"). Make sure
annotations are installed and enabled.)
【问题讨论】:
-
你安装
sensio/framework-extra-bundle了吗? -
@Federkun sensio/framework-extra-bundle 根据我的 composer.json 安装。有没有我应该采取的任何行动,但教程中没有?
标签: symfony routing annotations symfony4