Zend Framework 1.9: How to use Autoloading without

2019-01-22 04:49发布

how do i auto load zend framework classes when i am not using the MVC framework?

2条回答
孤傲高冷的网名
3楼-- · 2019-01-22 05:30

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

查看更多
登录 后发表回答