Autoloader.php 的register和load方法

register方法

  if (function_exists('__autoload')) {
            //    Register any existing autoloader function with SPL, so we don't get any clashes
            spl_autoload_register('__autoload');
        }
        //    Register ourselves with SPL
        return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));

 

load方法

 if ((class_exists($pClassName,FALSE)) || (strpos($pClassName, 'PHPExcel') !== 0)) {
            //    Either already loaded, or not a PHPExcel class request
            return FALSE;
        }

        $pClassFilePath = PHPEXCEL_ROOT .
                          str_replace('_',DIRECTORY_SEPARATOR,$pClassName) .
                          '.php';

        if ((file_exists($pClassFilePath) === FALSE) || (is_readable($pClassFilePath) === FALSE)) {
            //    Can't load
            return FALSE;
        }

        require($pClassFilePath);

 

spl_autoload_register这个方法会去自动注册方法,但是,PHPExcel自身有判断引入类的相对路径,和mvc的相对路径,就会因为相对路径的计算会出错,

spl_autoload_register('__autoload');注册 __autoload 方法因为相对路径的问题,如果你不嫌烦可以挨个处理路径的问题依然可以使用,但是也有简单办法,去吧register方法的经过的所有phpexcel方法全部注册一遍

,不管没有没先把可能在其他地方引入的或者注册的phpEXcel类全部spl_autoload_unregister一下,在应用的时候再去spl_autoload_register,

spl_autoload_register的作用是吧函数到注册到函数队列之中,
吧register 改成下面这样就可以在框架里面使用了
            $functions = spl_autoload_functions();
            foreach ( $functions as  $function){
                spl_autoload_unregister($function);
            }
            $functions = array_merge(array(array('PHPExcel_Autoloader','Load')),$functions);
            foreach ( $functions as $function){
                $x = spl_autoload_register($function);
            }
            return $x;

  

相关文章:

  • 2021-05-13
  • 2022-12-23
  • 2021-11-17
  • 2021-04-09
  • 2022-12-23
  • 2021-10-10
  • 2021-10-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-09
  • 2021-08-23
  • 2021-07-24
  • 2021-10-31
  • 2022-03-07
  • 2021-06-09
相关资源
相似解决方案