PHP RecursiveIteratorIterator:系统找不到指定的路径?

时间:2013-09-17 10:55:52

标签: php spl php-5.4 spl-autoload-register

当我想使用RecursiveIteratorIteratorspl_autoload_register自动加载课程时出现此错误,

  带有消息的

未捕获异常'UnexpectedValueException'   'RecursiveDirectoryIterator :: __ construct():系统找不到   路径指定。 (代码:3)

这是什么意思?

以下是我的班级自动加载器,

function autoload_multiple_directory($class_name){

    // List all the class directories in the array.
    $array_directories = array(
        'core/controller/', 
        'core/model/',
        'core/helper/',
        'core/ext/'
    );

    $parts = explode('\\', $class_name);

    // Set the class file name.
    $file_name = end($parts).'.php';

    foreach($array_directories as $path_directory){

        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path_directory),
            RecursiveIteratorIterator::SELF_FIRST
        );

        foreach ($iterator as $fileObject) {
            if ($fileObject->isDir()) {
                $files[] = str_replace('\\', '/', $fileObject->getPathname()).'/';
            }
        }


    }



    $array_directories = array_merge($array_directories,$files);

    // Loop the array.
    foreach($array_directories as $path_directory){
        if(file_exists(WEBSITE_DOCROOT.$path_directory.$file_name)){

            include WEBSITE_DOCROOT.$path_directory.$file_name;
        } 
    }
}


spl_autoload_register('autoload_multiple_directory');

错误行指向new RecursiveDirectoryIterator($path_directory),为什么?

1 个答案:

答案 0 :(得分:1)

我必须在new RecursiveDirectoryIterator(WEBSITE_DOCROOT.$path_directory)中使用绝对路径,因为有时会通过ajax调用init.php。