gpt4 book ai didi

symfony - 加载时未找到类 Controller

转载 作者:行者123 更新时间:2023-12-03 17:44:48 25 4
gpt4 key购买 nike

我正在用 Symfony 进行我的第一个项目,我创建了我的第一个 Controller 。并出现此错误。

problem image

我试过了

composer update



我遇到了同样的问题!
The problem that appear when i update the composer

这是 TestController.php 的代码
  <?php 
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class TestController extends Controller {
/**
* @Route("/")
* @Method ({"GET"})
*/
public function index()
{
//return new Response('<html><body>Hello world</body></html>');
return $this->render('articles/index.html.twig');
}

}

index.html.twig 文件只有一个 <h1> test </h1>在上面

是什么让这个问题出现?以及如何在不删除项目并重新创建的情况下修复它!
谢谢

最佳答案

Symfony\Bundle\FrameworkBundle\Controller\Controllerdeprecated since v4.2.0removed since v5.0.0 , 使用 Symfony\Bundle\FrameworkBundle\Controller\AbstractController反而。

<?php 

namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class TestController extends AbstractController {
/**
* @Route("/", methods={"GET"})
*/
public function index()
{
//return new Response('<html><body>Hello world</body></html>');
return $this->render('articles/index.html.twig');
}

}

关于symfony - 加载时未找到类 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59798041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com