1

Codeigniter で spl_autoload_register() を使用するにはどうすればよいですか? 自動ロードも使用する別のフレームワークで Codeigniter を使用しているため、これを行う必要があります。

ここで何かを見た

PHP spl_autoload_register

しかし、CodeIgniter autoload をターゲットにする方法がわかりません。OOPとCodeigniterは初めてです。どうもありがとう!

上記のリンクにはこれがあります:

function autoload_services($class_name){
    $file = 'サービス/' . $class_name. '.php';
    if (file_exists($file)){
        require_once($ファイル);
    }
}

function autoload_vos($class_name){
    $file = 'vos/' . $class_name. '.php';
    if (file_exists($file)){
        require_once($ファイル);
    }
}

関数 autoload_printers($class_name){
    $file = 'プリンター' . $class_name. '.php';
    if (file_exists($file)){
        require_once($ファイル);
    }
}

spl_autoload_register('autoload_services');
spl_autoload_register('autoload_vos');
spl_autoload_register('autoload_printers');
4

2 に答える 2

8

http://codeigniter.com/forums/viewthread/73804/#366081と、Twitter でフォローしている一部の CI 関係者からのいくつかの情報に感謝します (私は彼らに尋ねました): Eric BarnesDan HorriganPhil SturgeonZack Kitzmiller、解決策を見つけました。あなたが私のような CodeIgniter n00b である場合は、これらの人をフォローすることをお勧めします。

init.php と config.php を削除してから、CI の config.php の一番下に以下を詰め込みました (mylibrary というカスタム ライブラリからも自動読み込みしています)。

function multi_auto_require($class) {
if(stripos($class, 'CI') === FALSE && stripos($class, 'PEAR') === FALSE) {
    foreach (array('flourish', 'mylibrary') as $folder){
        if (is_file(APPPATH."../auxengines/{$folder}/{$class}.php")){
            include_once APPPATH."../auxengines/{$folder}/{$class}.php";
        }
    }
}
}

spl_autoload_register('multi_auto_require');

見事に動作します。ありがとう、人々!

于 2010-10-04T10:01:59.407 に答える
2

ああ、わかりました(以前の質問を見た後)... 2つの定義され__autoloadた関数があるため(したがって解析エラーが発生します)、問題が発生しています...

それを修正するには、それらのいずれかを別の名前に変更し、定義呼び出しの直後にspl_autoload_register('yournewfunctionname');...

私があなたの問題を理解している限り、それですべてです...

于 2010-10-01T19:19:11.130 に答える