Zend Framework 101: Zend_Loader
Creating Your Own Auto-Loader
If you have a different scheme for how your files are stored (for instance, you might use ClassName.class.php instead of ClassName.php), you can create your own auto-loader. To do so, you must create a class with a method called autoload() that accepts the name of a class as its only argument.
Listing 3 shows an example of such a class. Let's assume you store it in a file called MyAutoloader.php in your include directory.
Listing 3 Defining your own auto-loader (MyAutoloader.php)
class MyAutoloader { public static function autoload($class) { // define your logic in here for loading the class file } }
Next you must enable the auto-loader, as shown in Listing 4. Note that still only include Zend_Loader, since the registerAutoload() method will take care of loading your auto-loader.
Listing 4 Register your custom auto-loader (listing-4.php)
require_once('Zend/Loader.php'); Zend_Loader::registerAutoload('MyAutoLoader');




