首页 > 解决方案 > 加载时找不到类控制器

问题描述

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

问题图片

我尝试过了

作曲家更新

我遇到了同样的问题! 更新作曲家时出现的问题

这是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');
        }

    }

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

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

标签: symfonycontrollerwamp

解决方案


Symfony\Bundle\FrameworkBundle\Controller\Controller自 v4.2.0起已弃用,自 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');
    }

}

推荐阅读