Zend_Loader's autoloader deprecated in Zend Framework 1.8

Zend_Loader's autoloader has been deprecated in the upcoming Zend Framework version 1.8 and so you now get a notice if you use it:

Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /www/zf-tutorial/library/Zend/Loader.php on line 207

Notice: Zend_Loader::Zend_Loader::autoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /www/zf-tutorial/library/Zend/Loader.php on line 186

Notice: Zend_Loader::Zend_Loader::autoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in /www/zf-tutorial/library/Zend/Loader.php on line 186

(and so on)

This is because you have the lines:

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

(or similar) somewhere in your bootstrap system.

The easiest solution is to change them to:

require_once 'Zend/Loader/Autoloader.php';
$loader Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('App_');

Where 'App_' is the name of a directory on your include path that has classes within it that follow the Zend Framework naming convention, so change it as appropriate and add more if you need them.

If you need generic autoloading ability, for instance because your models directory is on your include path and you don't namespace your model classes, then add this:

$loader->setFallbackAutoloader(true);

You should also add:

$loader->suppressNotFoundWarnings(false);

when in development mode as then the new autoloader will actually tell you what the syntax error is rather than showing you a white page :)

Now you should go and read the Zend_Loader_Autoloader documentation to learn how very useful it is!

Update: You should also read Matthew's article on Zend_Loader_Autoloader as it explains this all in detail!

posted @ 2010-10-24 07:33  春哥也编程  阅读(347)  评论(0编辑  收藏  举报