Search code examples
phpcakephpcakephp-3.0vendor

Cakephp 3 loading vendor files


In cakephp 2 when I need a vendor or related class to be loaded globally, i was adding require or app use inside bootstrap.php ot core php.

In cakephp 3 where should I require vendor files ? I dont want to declare vendor require in every class and template file that I use my vendor files.

http://book.cakephp.org/3.0/en/core-libraries/app.html#loading-vendor-files


Solution

  • Vendor files are 3rdparty files. You custom static utility classes are not vendor files but rather your app files. You can put them under src/Lib/. Just ensure to use proper namespace for the classes and add proper use statement wherever you need to use your class.

    For e.g. if your lib class is src/Lib/FooBar.php then it should have classname App\Lib and the "use" statement would be use App\Lib\FooBar.