Setting Up Zend Framework 2 Autoloader

May 13th, 2014

If you’re like me, you like to dig into the belly of things and twist them to your own uses. Tonight, I’ve been monkeying around with ZF2 autoloaders, and working out how they function.

I store my ZF install in a dir (Zend/) in my include path, so I don’t have to maintain copies for each site on my server.

Some useful notes on this:

The stock ZF2 download does not include a pre-generated classmap file. To generate this, go into the default unpacked archive folder, into bin/ and run this command:

php classmap_generator.php -l "/usr/share/php/Zend/"

[code language=”php”]
// How to get an absolute path to the generated classmap file (return: /usr/share/php/Zend/autoload_classmap.php)
$classmapPath = stream_resolve_include_path(‘Zend/autoload_classmap.php’);

// How to get the autoload up and running
require_once ‘Zend/Loader/ClassMapAutoloader.php’;
$autoloader = new Zend\Loader\ClassMapAutoloader();
$autoloader->registerAutoloadMap($classmapPath);
$autoloader->register();
[/code]

That’s all for tonight folks!

WordPress - Entries (RSS) and Comments (RSS) - © 2011 Ben Dauphinee