PHP PSR-4-未找到类

PHP PSR-4-未找到类,php,composer-php,autoload,vendor,Php,Composer Php,Autoload,Vendor,我已经用PHP添加了我的名称空间,但无法让它工作 我的设置有什么问题?当我想调用我的测试类时: https://hilfe.kbs-community.de/index.php?controller=TanoaLife&params=123 我收到错误消息: 未找到类“KWinkel\Helpdesk\Controller\TanoaLife” 我的设置: index.php <?php error_reporting(E_ALL); ini_set('display_erro

我已经用PHP添加了我的名称空间,但无法让它工作

我的设置有什么问题?当我想调用我的测试类时:

https://hilfe.kbs-community.de/index.php?controller=TanoaLife&params=123
我收到错误消息:

未找到类“KWinkel\Helpdesk\Controller\TanoaLife”

我的设置:

index.php
<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');
ob_start('ob_gzhandler');

// autoloader 
$Autoloader = require __DIR__ . '/vendor/autoload.php';
$Autoloader->add('KWinkel\\Helpdesk\\', 'app/');

// controller
if ( isset($_GET["controller"]) ) {
    $Controller = $_GET["controller"];
    if ( file_exists("app/Controller/" . $Controller . ".class.php") ) {
        $Class = "KWinkel\Helpdesk\Controller\\" . $Controller;
        new $Class($_GET["params"]);
    } else {
        echo "invalid call #1";
    }
} else {
    echo "invalid call #2";
}

$SysContent = ob_get_contents();
ob_end_clean();
echo $SysContent;

?>


app/Controller/TanoaLife.class.php
<?php
namespace KWinkel\Helpdesk\Controller;

class TanoaLife extends AbstractController {
    //

    function __construct ($Params) {
        echo "params: " . $Params;
    }

}


?>
index.php

您的类文件
TanoaLife.class.php
应该如下所示:

 namespace KWinkel\Helpdesk\Controller;

 class TanoaLife {

 }
应该放在这里:

app/Controller/TanoaLife.class.php

使用自动加载器

更新:我希望将类文件命名为
TanoaLife.php
而不是
TanoaLife.class.php
,或者您必须设置
autoloader
以包含后缀为
.class.php

$Autoloader->addPsr4('KWinkel\\Helpdesk\\','app')


在定义TanoaLife的类文件中定义名称空间
KWinkel\Helpdesk\Controller
?代码图片无效,请将相关代码粘贴到您的问题中。对不起,我已经添加了代码和文件路径。情况已经如此,我已经在您的autloader的第一个postDid中添加了一些信息,现在他在尝试加载类名时必须将.class.php而不是.php添加到类名中?不,我已经从index.php文件路径中删除了.class。它无论如何都不起作用。也来自您的
文件\u exists()
部分?是(未找到类“KWinkel\Helpdesk\Controller\TanoaLife”)。我是否需要比在index.php(Autoloader->add..)中做更多的事情?