问题
How can I use the Symfony2 ClassLoader to autoload classes that dont follow PEAR naming conventions and don't use namespaces?
It seems from the symfony2 docs that this isn't possible. How does one include API helper libraries or other files that don't follow these types of conventions (i.e. they instead follow Zend conventions or no naming conventions at all)?
回答1:
You should register autoloading functions for those classes using spl_autoload_register(). This will let you have several autoloaders rune one after another, until one manages to load requied class.
回答2:
Code example of what Mchl said
in app/autoload.php
...
$loader->register();
...
/////////////////////////////////////////////////////////////////////////////////
// Own autoloader for non-namespaced nor PEAR lib. Replace tcpdf with yours.
function myLoader()
{
$file = __DIR__ . '/../vendor/tcpdf/tcpdf.php';
if (!file_exists($file))
{
return false;
}
require_once $file;
}
spl_autoload_register('myLoader');
来源:https://stackoverflow.com/questions/9253477/autoload-classes-with-zend-based-naming-convention-or-no-convention-at-all-with