可以找到一个PHP类,但不能找到另一个

我正在使用Slim 4框架并试图使路由正常工作,但是我一生都无法弄清为什么找不到我的控制器文件。我习惯于Laravel为我处理所有这些事情,但是我想尝试Slim作为我的最新应用程序。

I have been using http://www.slimframework.com/docs/v4/objects/routing.html as my guide and want my routes to be defined like ControllerHere:FunctionHere, but for some reason is does not work.

在我的index.php中,我包含了一个route.php文件,其内容为

namespace App;

$app->get('/test1', Test1Controller::class.':home');

$app->get('/test2', '\Test2Controller:home');

然后,我有两个文件:Test1Controller和Test2Controller,它们都与我的route.php文件位于同一应用程序文件夹中。按照链接中的指南,我的/ test1路由和Test1Controller可以完美加载,但是我无法使Test2Controller正常工作,其代码为:

namespace App;

use Psr\Container\ContainerInterface;


class Test2Controller {

    protected $container;


    public function __construct(ContainerInterface $container) {
        $this->container = $container;
    }


    public function home($request, $response, $args) {
        $response->getBody()->write("Hello world test2!");
        return $response;
    }

}

有人可以看到我在做什么吗?我得到的错误是: PHP致命错误:未捕获RuntimeException:可调用\ Test2Controller不存在