Switch from Zend_Loader to Zend_Loader_Autoloader


Zend_Loader

Zend_Loader was the usual kind of autoloading in Zend Framework before version 1.8. Than simply you say:

require_once “Zend/Loader.php”;
Zend_Loader::registerAutoload();

That made all your application to autoload files from the library folder where usualy the Zend Framework stays. That has several things to be changed.

The namespaces

There where not really namespaces for autoloading. Everything was searched to be loaded in one single namespace. And thus there where not the functionality to remove a namespace from the game. You have everything all the time.

Zend_Loader_Autoloader

This is new from version 1.8 in Zend Framework. Now you should use this class to autoload your classes. There’s really namespaces and for more info and detailed information you should search the documentation of the ZF.

The most simple way to switch from Zend_Loader to Zend_Loader_Autoloader

That’s really simple, and I don’t understand why there’s not proper explanation how to do that in the ZF docs. You need to replaces this lines of code:

require_once “Zend/Loader.php”;
Zend_Loader::registerAutoload();

with these:

require_once ‘Zend/Loader/Autoloader.php’;
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);

or more  simple

require_once ‘Zend/Loader/Autoloader.php’;
$autoloader = Zend_Loader_Autoloader::getInstance();

From http://framework.zend.com/manual/en/zend.loader.autoloader.html

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s