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!

April 30th, 2009 at 07:26 #
Your title is a bit misleading, not the whole Zend_Loader is deprecated but the autoloading facilities.
Zend_Loader::loadClass() for example is used by Zend_Loader_Autoloader.
April 30th, 2009 at 09:37 #
Jan,
You are right. I have fixed the title.
Regards,
Rob...
April 30th, 2009 at 22:53 #
I liked
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
it's simple, two lines, no messing around :)
May 1st, 2009 at 14:02 #
Thanks a lot, you save my time!!
stefano
May 1st, 2009 at 17:57 #
hey guys,
this new method doesn't seem to work with my code... I used the autoloader just to autload zend_pdf (i replaced all require_once references and the autoloader requires automaticly the needed zend_pdf files..) can anybody help me with that? this is my old code:
May 1st, 2009 at 17:57 #
my code:
// LOAD ZEND_PDF
$path = '../system/plugins';
set_include_path( get_include_path().PATH_SEPARATOR.$path );
require_once $path.'/Zend/Loader.php';
Zend_Loader::registerAutoload();
Zend_Pdf::load('test.pdf');
May 3rd, 2009 at 00:20 #
@mvug
As mentioned above Zend_Loader::registerAutoload() is deprecated. So I dont think its useful to give hints for this feature since now ;)
May 5th, 2009 at 14:05 #
Hi Rob,
thanks for your advice.
May 7th, 2009 at 21:21 #
When you say:
'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:'
What do you mean by namespacing model classes? What is the best practice here?
Thanks.
May 8th, 2009 at 05:27 #
benr,
Best practice for an article model in a CMS module would be to call it Cms_Model_Article or similar. This would make it less likely to conflict with another class when moving your CMS module to a different app.
Regards,
Rob...
May 10th, 2009 at 08:31 #
Maybe im an idiot, but I cant seem to get this working...
My code looks like the following (note I have uncommented and commented different portions unsuccessfully)
require_once "Zend/Loader/Autoloader.php";
//require_once "doctrine/Doctrine.php";
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Wfm_');
$autoloader->setFallbackAutoloader(true);
//$autoloader->pushAutoloader(array('Doctrine', 'autoload'), 'Doctrine');
I have a folder in my /library called Wfm with a number of classes, however, it fatals out on the first inclusion of a Wfm_ prefixed file. The path looks like...
/library/Wfm/Layout/Controller/Plugin/Layout.php - However, it complains that it cannot find the file, or the class does not exist within the file. My PHP include path includes the library folder - am I just missing something obvious here?
May 10th, 2009 at 08:54 #
Ben,
Assuming the class is called Wfm_Layout_Controller_Plugin_Layout within layout.php, I can't see anything obvious. Sorry.
I'd double check the output of get_include_path() too.
Regards,
Rob...
May 10th, 2009 at 09:05 #
Rob,
Thanks for the quick response. Unless ive gone absolutely mad, im 100% sure that the file is there. I copied the entire Wfm folder from another project where it worked without issue.
It seems, at this point, to only be an issue with that file, as odd as that sounds, if I remove the line in the bootstrap:
Zend_Layout::startMvc(array(
'layoutPath' => APP_DIR . DS . 'layouts',
'pluginClass' => 'Wfm_Layout_Controller_Plugin_Layout'
));
Then it loads up saying it cant find the index controller which makes sense because its a new project - it doesnt fatal out, so I assume its working.
The include path looks correct, here is the first portion of it... Warning: include() [function.include]: Failed opening 'Wfm\Layout\Controller\Plugin\Layout.php' for inclusion (include_path='C:\Workspace\Projects\XXXXXX\site\library;
Excluding other include path's - that one right there should cover it assuming the file is in C:\Workspace\Projects\XXXXXX\site\library\Wfm\Layout\Controller\Plugin\Layout.php
I guess the last thing I can say is that this entire config, file structure, etc works on pre 1.8 applications without fail.
May 10th, 2009 at 09:10 #
I take that back.. anything under the Wfm_ namespace fails miserably..
June 3rd, 2009 at 07:54 #
hi
setting probleam accured
why
June 10th, 2009 at 10:47 #
Hi,
Thanks for your tutorial. Found it really helpful.
It's a shame the ZF manual doesn't explain this in such a simple, straight forward way.
June 22nd, 2009 at 19:47 #
Hey Rob, thanks for your great article (again) :)
I upgraded to 1.8.3 and got the above mentioned error message.
Am I right when this:
include_once('Zend/Loader/Autoloader.php');
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);
Is the same as the previously used:
include_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
It appears to be that way in my current app.
June 23rd, 2009 at 06:56 #
GP,
Yes. I suspect that suppressNotFoundWarnings may be set to false by default nowadays, but it never hurts to be explicit.
Regards,
Rob...
July 1st, 2009 at 03:05 #
Recently I started to get familiar with the MVC and I was recomended to work with Zend Framework, but it has taken me several days trying to configure the Boostrap.php, the .htacces and index.php on public folder, so far it works for the IndexController and ErrorController, but when adding new controllers is not very clear how should I call them, because I can not even define who is the front controller, I need a basic setup to begin to develop an application, the base. Could someone help me?
July 21st, 2009 at 22:32 #
guelmismr>>>
http://akrabat.com/zend-framework-tutorial/
Try the new 1.8 version of Rob's Tutorial it looks fresh and easy, will begin to poke holes on my punch cards tomorrow before running the codes :-)
By the way guelmismr it has taken me around 360 days (~12 months) to configure LAMP/WAMP, Bootstrapper, .htaccess, index.php, reading the basic chapters of ZFiA etc. etc.
I still haven't been able to play with the HTML and CSS part yet, maybe tomorrow when my punch cards are hot and ready :-)
August 31st, 2009 at 13:21 #
thank's a lot, i found this really useful!
February 12th, 2010 at 17:43 #
I am currently redoing my website using zend framework and chose your book. The zf version is 1.9.7 . Page 71...The baseUrl View Helper. The getBaseUrl() now includes index.php in 1.9.7...so you need to strip it out in the view helper:
i.e.
class Places_View_Helper_BaseUrl
{
function baseUrl()
{
$fc = Zend_Controller_Front::getInstance();
$baseUrlWithIndex = $fc->getBaseUrl();
$base_url = substr($_SERVER['PHP_SELF'], 0, -9);
return $this->_baseUrl = $base_url;
}
}
February 12th, 2010 at 20:37 #
An adjustment to my comment. You can't just strip out index.php. You need to set the baseUrl.
February 18th, 2010 at 01:52 #
Using ZF 1.10.1 and Zend_Tool.
Listing 2.1 differs greatly from the index.php file that Zend_Tool places in the public folder.
Have things changed that much since ZF 1.5? Can I still use this book?
February 18th, 2010 at 07:39 #
Frank,
Yes the book is still useful for ZF development. However, the MVC chapters, (2, 3 & 4) are less useful nowadays. Essentially, you need to go through my tutorial and then look at how 2,3,4 differ.
Regards,
Rob...