【问题标题】:Class Controller not found while loading加载时找不到类控制器
【发布时间】:2020-01-18 06:18:39
【问题描述】:

我正在使用 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 文件上只有一个&lt;h1&gt; test &lt;/h1&gt;

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

【问题讨论】:

  • 请不要在提问中使用图片。只需复制/粘贴相关行并将它们放入代码块中。下面的答案是正确的。考虑承认它。
  • 好的,我明白了:)
  • 这里有人和我一样的教程,哈哈

标签: symfony controller wamp


【解决方案1】:

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-26
    • 2018-12-15
    • 2012-10-15
    • 2017-03-17
    • 1970-01-01
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多