16

Hello I am trying to use SILEX micro framework together with my own library full of classes and therefore I am stuck with 2 loaders that results in a error that the loader can't load classes.. Is there a way to use these 2 loaders simultaneously without getting this error?

the loader that I use you can find below:

    <?php

/*
 * Loader
 */

function my_autoloader($className) 
{
// haal de base dir op.
  $base = dirname(__FILE__);


  // het pad ophalen
  $path = $className;

  // alle paden samenvoegen tot waar ik zijn moet en de phpfile eraan plakken.
  $file = $base . "/lib/" . $path . '.php';       

  // als file bestaat haal op anders error
  if (file_exists($file)) 
  {
      require $file;
  }
  else 
  {
      error_log('Class "' . $className . '" could not be autoloaded');
      throw new Exception('Class "' . $className . '" could not be autoloaded from: ' . $file); 
  }
}

spl_autoload_register('my_autoloader');

?>

the loader that silex uses is in the vendor directory ( from the framework itself )

and this is how my file tree looks like:

filetree

4

1 に答える 1

39

オートローダー関数でエラーをスローしないでください。 spl_autoload_registerは、php が登録されているすべてのオートローダーを順番に通過できるようにしますが、そのプロセスの途中でキャッチされないエラーをスローすると、次のオートローダーを試すことができません。

http://php.net/spl_autoload_register

于 2012-11-12T14:25:33.407 に答える