Autoload custom library in Zend Framework 2.0

后端 未结 5 1218
刺人心
刺人心 2020-12-13 16:52

I need to use autoloading for my custom classes in Zend Framework 2.0. My custom library located in /vendor/Garvey/library/Garvey. I have a sim

5条回答
  •  清歌不尽
    2020-12-13 17:18

    Matthew Weier O'Phinney explains in this video that there are now 3 methods for autoloading :

    • ZF1-style include_path autoloader ( old zf1 method, not recommended )
    • Per-namespace/prefix autoloading ( new zf2 method, better )
    • Class-map autoloading ( recommended and the fastest )

    A class-map generator utility is mentioned in the docs that will take care of writing the /vendor/vendor_name/library/autoload_classmap.php for you.

    The solution you found is similar to the one Matthew mentions in the video for the Per-namespace/prefix autoloading. Following the code structure in ZendSkeletonApplication, that code would go in the /init_autoloader.php file, rather than in the /public/index.php file.

提交回复
热议问题