Composer错误 - 找不到类

时间:2015-08-05 18:05:35

标签: php namespaces composer-php

我收到以下错误:

  

致命错误:第36行的/var/sites/t/websitename/app/lib/Loader.php中找不到“控制器\错误”类

这是相关文件的内容:

<?php
namespace Lib;

use Controller\Login;
use Controller\Supervisor;
use Controller\Traffic;
use Controller\Error;

class Loader
{
private $_controller;
private $_urlvalues;

// store the URL values on object creation
public function __construct($urlvalues)
{
    if (! isset($urlvalues['controller'])) {
        $this->_urlvalues  = $urlvalues;
        $this->_urlvalues['controller'] = 'Login';
        $this->_controller = '\\Controller\\Login';
    } else {
        $this->_urlvalues  = $urlvalues;
        $this->_controller = '\\Controller\\' .
            $this->_urlvalues['controller'];
    }
}

// establish the requested controller as an object
public function CreateController()
{
    // does the class exist?
    if (class_exists($this->_controller)) {
        return new $this->_controller($this->_urlvalues);
    } else {
        // bad controller error
        return new \Controller\Error();
    }
}
}

以下是我的composer.json文件:

{
"require-dev":
{
    "phpunit/phpunit": "4.7.*",
    "phpdocumentor/phpdocumentor": "2.*"
},

"autoload":
{
    "psr-4":
    {
            "Controller\\"  : "app/controller/",
            "Core\\"                : "app/core/",
            "Lib\\"         : "app/lib/"
    }
},

"minimum-stability": "dev",
"prefer-stable": true
}
?>

文件肯定存在于“app / controller /”文件夹中,大写 - 小写字母相同。

有人可以帮忙吗?

BTW有问题的文件在我的public_html文件夹(浏览器中可见的文件夹)之外,可能是相关的吗?

1 个答案:

答案 0 :(得分:1)

你说

use Controller\Error;

位于顶部,因此您稍后可以使用return new Error();