CakePHP - Include class from a directory outside the app directory

安稳与你 提交于 2019-12-06 14:15:30

Loading shouldn't be done in your bootstrap, but in your AppController's beforeFilter method instead.

Also, there is a reserved place for non-Cake libraries, being the app/Vendor directory. You can place all your classes in there and then load team easily with:

App::uses('MyClass', 'Vendor');

If it really needs to be in an alternative path, you need to specify and call the full path instead. And make sure to use the same names. Right now, you're specifying Lib, yet calling CakePHP as if that was a build by itself (which it's not). This won't work. It should look like this instead:

App::build(array('Lib' => array('/var/www/websites/lib')));
App::uses('MyClass', 'Lib/CakePHP'); // Define the subdirectory here

Also check the documentation on loading vendor files, it has quite some examples.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!