Php 自动加载&x2B;名称空间在localhost中工作,但不';不能在服务器上工作

Php 自动加载&x2B;名称空间在localhost中工作,但不';不能在服务器上工作,php,.htaccess,ubuntu-14.04,digital-ocean,Php,.htaccess,Ubuntu 14.04,Digital Ocean,我有一个可以在本地主机上运行但在我的服务器上不工作的代码,我有一个名为platform的文件夹路径是/var/www/html/platform 平台/.htaccess AcceptPathInfo On RewriteEngine on RewriteBase /var/www/html/platform/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ i

我有一个可以在本地主机上运行但在我的服务器上不工作的代码,我有一个名为platform的文件夹路径是
/var/www/html/platform

平台/.htaccess

AcceptPathInfo On
RewriteEngine on
RewriteBase /var/www/html/platform/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?request=$1 [L,QSA]
plataform/autoload.php

function __autoload($className) {
$file = $className . '.php';
if(file_exists($file)) {
     require_once $file;
}else{
    //fail
}
include ('autoload.php');

$controller = new application\controllers\Controller();
namespace application\controllers;

class Controller{

}
plataform/index.php

function __autoload($className) {
$file = $className . '.php';
if(file_exists($file)) {
     require_once $file;
}else{
    //fail
}
include ('autoload.php');

$controller = new application\controllers\Controller();
namespace application\controllers;

class Controller{

}
plataform/application/controllers/Controller.php

function __autoload($className) {
$file = $className . '.php';
if(file_exists($file)) {
     require_once $file;
}else{
    //fail
}
include ('autoload.php');

$controller = new application\controllers\Controller();
namespace application\controllers;

class Controller{

}
在我的localhost中,此代码有效,但在我的服务器中,我收到以下消息:

致命错误:在中找不到类“应用程序\控制器\控制器” /var/www/html/platform/index.php,第12行

我怎样才能解决这个问题?我正在14.04(数字海洋)上使用Ubuntu
PHPMyAdmin

注册自动加载器。 * *根据此处找到的官方PSR-4自动装弹机示例: *

这是一个简单的自动加载类,也应该处理名称空间

class Autoload {

    public function __construct(){

    spl_autoload_register(function ($class) {

        // project-specific namespace prefix
        $prefix = 'App\\';

        // For backwards compatibility
        $customBaseDir = '';

        // base directory for the namespace prefix
        $baseDir = $customBaseDir ?: __DIR__ . '/';

        // does the class use the namespace prefix?
        $len = strlen($prefix);
        if (strncmp($prefix, $class, $len) !== 0) {
            // no, move to the next registered autoloader
            return;
        }

        // get the relative class name
        $relativeClass = substr($class, $len);

        // replace the namespace prefix with the base directory, replace namespace
        // separators with directory separators in the relative class name, append
        // with .php
        $file = rtrim($baseDir, '/') . '/' . str_replace('\\', '/', $relativeClass) . '.php';

        // if the file exists, require it
        if (file_exists($file)) {
            require $file;
        }   
    });
}
}
保存在Autoload.php类中。包含路径并初始化以使用$自动加载=新的自动加载

注册自动加载器。 * *根据此处找到的官方PSR-4自动装弹机示例: *

这是一个简单的自动加载类,也应该处理名称空间

class Autoload {

    public function __construct(){

    spl_autoload_register(function ($class) {

        // project-specific namespace prefix
        $prefix = 'App\\';

        // For backwards compatibility
        $customBaseDir = '';

        // base directory for the namespace prefix
        $baseDir = $customBaseDir ?: __DIR__ . '/';

        // does the class use the namespace prefix?
        $len = strlen($prefix);
        if (strncmp($prefix, $class, $len) !== 0) {
            // no, move to the next registered autoloader
            return;
        }

        // get the relative class name
        $relativeClass = substr($class, $len);

        // replace the namespace prefix with the base directory, replace namespace
        // separators with directory separators in the relative class name, append
        // with .php
        $file = rtrim($baseDir, '/') . '/' . str_replace('\\', '/', $relativeClass) . '.php';

        // if the file exists, require it
        if (file_exists($file)) {
            require $file;
        }   
    });
}
}

保存在Autoload.php类中。包含路径并初始化以使用$自动加载=新的自动加载

您的自动加载是否符合PSR-4标准?此外,您还研究了spl_自动加载。@MueyiwaMosesIkomi PSR-4标准?spl_自动加载?这对我来说是新的。。。我不明白你在说什么。。。你有教程或类似的东西吗?我将发布一个关于如何处理自动加载的答案,在我实现的任何地方都可以使用。关于这个:
$file='./'$类名。php′@Kazz不工作…您的自动加载是否符合PSR-4标准?此外,您还研究了spl_自动加载。@MueyiwaMosesIkomi PSR-4标准?spl_自动加载?这对我来说是新的。。。我不明白你在说什么。。。你有教程或类似的东西吗?我将发布一个关于如何处理自动加载的答案,在我实现的任何地方都可以使用。关于这个:
$file='./'$类名。php′@Kazz不起作用。。。