2016-04-12 11 views
0

hata için bir sınıf çağırma olduğunuHata:</p> <blockquote> <p>Class 'ControllerIndex' not found</p> </blockquote> <p>ama her an bütün kodda ben bu sınıfı diyoruz: Sebepsiz

test.php < < Script Executor

include_once("index.engine.php"); 
Index::importController(); 
use Controller\User; 
echo User::getWorld(); // The error happens here. 

Index.engine.php < < yılında dexer içerir

if (!defined('HOME')) define("HOME", __DIR__."/"); 

class Index{ 

    public static function importModel(){   
     spl_autoload_register(function ($class) { 
      $nome = str_replace("\\", "/" , $class . '.model.php'); 
      if(file_exists(HOME . $nome)){ 
       include_once(HOME . $nome); 
      } 
     }); 
    } 

    public static function importController(){ 
     spl_autoload_register(function ($class) { 
      $nome = str_replace("\\", "/" , $class . '.controller.php'); 
      if(file_exists(HOME . $nome)){ 
       include_once(HOME . $nome); 
      } 
     }); 
    } 

    public static function importPersistent(){ 
     spl_autoload_register(function ($class) { 
      $nome = str_replace("\\", "/" , $class . '.persistent.php'); 
      if(file_exists(HOME . $nome)){ 
       include_once(HOME . $nome); 
      } 
     }); 
    } 

} 

user.controller.php < < < < Fonksiyon yardım

namespace Persistent{ 
    class Test{ 
     public static function getEngine(){ 
      $engine = "Engine is on! \o/"; 
      return $engine; 
     } 
    } 
} 

Teşekkür gerekli Yalnızca bir ara

 namespace Controller{ 
    include_once (__DIR__ ."/../index.engine.php"); 
    Index::importPersistent(); 
    use Persistent\Test; 
     class User{ 
      public static function getWorld(){ 
       $result = Test::getEngine(); 
       return $result; 
      } 
     } 
    } 

user.persistent.php ben mi. Bunun için

cevap

0

user.controller.php

namespace Controller{ 
include_once (__DIR__ ."/../index.engine.php"); 
Index::importPersistent(); 
use Persistent\Test; 
    class User{ 
     public static function getWorld(){ 
      $result = Test::getEngine(); 
      return $result; 
     } 
    } 
} 

bir dosya olması beklenen Değiştir:

namespace Controller{ 
use Index; 
use Persistent\Test; 
Index::importPersistent(); 
    class User{ 
     public static function getWorld(){ 
      $result = Test::getEngine(); 
      return $result; 
     } 
    } 
} 

hata sadece bir kez görünümünde dönmesini sonra değiştirilmiş, bir kez daha denilen dahil olduğu oldu.

0
use Controller\User; # this is used to call a namespace, in your code there is no declaration of the namespace 
echo User::getWorld(); // 

, kimse bu formu

sample.php

namespace Controller; 

class User { 
    public static function getWorld() { 
    ... 
    } 
} 
+0

Evet, doğru, ama kontrolü çağırmak ve komutu çalıştırmak istiyorum ... sorun, "indeksini" içe aktarmaya çalışıyor olması ve bunu istemiyorum. –

+0

Sizi doğru anlarsam, denetleyiciden getWorld() yöntemini çağırmak ister misiniz? – cookies

+0

http://prntscr.com/ar5q98 - Test dosyası için kontrol yöntemini arıyorum. –

İlgili konular