how do i auto load zend framework classes when i am not using the MVC framework?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The nice thing about the Zend framework is that it's extremely modular, you can use just about any piece of it you want without adopting the whole thing.
For example, we can use Zend_Loader_Autoloader
to set up class auto-loading without having to use Zend_Application
First make sure the Zend library is in your include path:
set_include_path('/path/to/zend/' . PATH_SEPARATOR . get_include_path());
Then require the Autoloader class:
require_once 'Zend/Loader/Autoloader.php';
Then we set up the autoloader:
// instantiate the loader
$loader = Zend_Loader_Autoloader::getInstance();
// specify class namespaces you want to be auto-loaded.
// 'Zend_' and 'ZendX_' are included by default
$loader->registerNamespace('My_App_');
// optional argument if you want the auto-loader to load ALL namespaces
$loader->setFallbackAutoloader(true);
Once the auto-loader is set up (preferably in a bootstrap or something), you can call Zend framework classes (or your own app's classes) without having to require them individually:
$foo = new Zend_Library_Class();
$bar = new My_App_Class();
Read more about it in the documentation
回答2:
See: http://us.php.net/manual/en/language.oop5.autoload.php