web developing
10 May
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.
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.
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.
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);
Related posts:
15 Responses for "Switch from Zend_Loader to Zend_Loader_Autoloader"
Thanks so much.. it’s easier after reading your article and it must be documented in zend framework doc too.
Thanks for this! I’ve just installed Zend for the first time, and I just wanted to get up and running as quick as possible.
Hi Michael,
it’s great I have helped you! I’d be glad to share my experience with Zend Framework if you have more questions.
greetings
actually its enough to write
require_once ‘Zend/Loader/Autoloader.php’;
Zend_Loader_Autoloader::getInstance();
the ctor of Zend_Loader_Autoloader registers itself [:
Great, worked like a charm.
Thank you!
Finally, the answer! Perfect, thanks for sharing this. I bought a book on ZF and its already out of date!
Thanks. It’s been a while since I last played with ZF and a lot has changed.
Thanks
kkk says that this line is not necessary
$autoloader->setFallbackAutoloader(true);
But if we dont use it, there will be an error. I got this error:
Fatal error: Class ‘Templater’ not found in C:\xampp\htdocs\phpweb20\htdocs\index.php on line 36
The line 36 of my code is
$vr->setView(new Templater());
When I included all three lines of code:
require_once (‘Zend/Loader/Autoloader.php’);
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
the error vanished.
Great!
Thank you very much, I was wondering how to get use of the different classes of zendframework without setting up an application¡¡ It was worthy ¡¡ Thanks
hi, Abhishek Kumar,
I just reading the same book as yours. the samethings happened like yours.
chinese words are “,同是天涯沦落人,相逢何必曾相识”, that says we meets same things.
I finally found it Thank you sir!
@stoimen – very good helped me a lot
@barbas – thanks! glad to help
Leave a reply