2016-10-04 6 views
1

私は実際には以下の使用して、クラス名とコントローラ、モデルとエンティティをロードする非常に古いアプリケーションスクリプトを持っている今、私も作曲で、第三者オートローダの統合に問題があるPHPのオートローダーの問題

function __autoload($className) 
{ 
    list($filename , $suffix) = explode('_' , $className); 

    switch (strtolower($suffix)) 
    { 
     case 'model': 

      $folder = '/model/';    
      $suffix = BIZ_SUFFIX; 

     break; 

     case 'dao': 

      $folder = '/entity/'; 
      $suffix = DAO_SUFFIX;   

     break;  
    } 

    $file = SITE_PATH . $folder . strtolower($filename) . $suffix .'.php';  
    if (file_exists($file)) 
    {  
     include_once($file);   
    } 
    else 
    {  
     die("File '$filename' containing class '$className' not found in '$folder'."); 
    } 
} 

スニペットオートロード。

私もエラーMSG

同様の方法を下回る
spl_autoload_register(function ($class) { 
    include 'classes/' . $class . '.class.php'; 
}); 

function my_autoloader($class) { 
    include 'classes/' . $class . '.class.php'; 
} 

spl_autoload_register('my_autoloader'); 

を試してみました:

Fatal error: Class 'Template_Model' not found 

答えて

0

あなたがspl_autoload_registerを使用する場合は、__autoload関数はなりませんと呼ばれる。

__autoloadの名前を変更する。 old_autoload。オートローダに登録してくださいspl_autoload_register('old_autoload');

+0

私はすでに試してみましたが、残念ながらうまくいきませんでした。たとえば、swiftmailerを使用している場合、swiftmailerのオートローダーはロードされず、オートローダー機能がロードされます。 –

+0

この部分を削除する 'die(" $ folderNameに '$ className'クラスが含まれている '$ filename'ファイルが見つかりません。 'あなたのオートローダーから –