Zend Framework 1.9: How to use Autoloading without MVC

后端 未结 2 1228
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 04:57

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

相关标签:
2条回答
  • 2020-12-14 05:31

    See: http://us.php.net/manual/en/language.oop5.autoload.php

    0 讨论(0)
  • 2020-12-14 05:44

    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

    0 讨论(0)
提交回复
热议问题