2016-11-01 11 views
1

Ich habe diesen einen Code, der in localhost funktioniert, aber in meinem Server nicht funktioniert, habe ich einen Ordner namens Plattform der Pfad /var/www/html/platformAutoload + Namespace arbeitet in localhost, aber funktionieren nicht in Server

Plattform/.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 
} 

plataform/index.php

include ('autoload.php'); 

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

plataform/application/controllers/Controller.php

namespace application\controllers; 

class Controller{ 

} 

In meinem localhost dieser Code funktioniert, aber in meinem Server erhalte ich die folgende Meldung:

Fatal error: Class 'application\controllers\controller' not found in /var/www/html/platform/index.php on line 12

Wie kann ich dieses Problem lösen? Ich benutze Ubuntu PHPMyAdmin on 14.04 (Digital Ocean).

+0

Entspricht Ihr Autoloading dem PSR-4-Standard? Außerdem schaust du in spl_autoloading. –

+0

@MueyiwaMosesIkomi PSR-4 Standard? spl_autoloading? Das ist neu für mich ... Ich verstehe nicht, worüber du sprichst ... Du hast ein Tutorial oder ähnliches? – Lacrifilm

+0

Ich werde eine Antwort auf, wie ich mit meinem Autoload umgehen, funktioniert überall wo ich implementieren –

Antwort

0

Registrieren Sie den Autoloader. * https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md

Hier ist eine einfache automatische Laden-Klasse ist, sollte mit Namensräumen zu

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

speichert in Autoload.php Klasse beschäftigen: * * hier das offizielle PSR-4 Autoloader Beispiel basiert. Pfad einschließen und initialisieren, um zu verwenden. $ autoload = new Autoload;

Verwandte Themen