[加载时未找到类控制器

问题描述 投票:1回答:1

我正在与Symfony一起进行第一个项目时,创建了第一个控制器。并且出现此错误。

problem image

我尝试过

作者更新

而且我遇到了同样的问题!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 controller wamp
1个回答
0
投票

[Symfony\Bundle\FrameworkBundle\Controller\Controller分别为deprecated 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');
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.