WHere to save a custom class and how to load it in a CakePHP Component?

做~自己de王妃 提交于 2019-12-05 16:06:08

If you wrote the custom class, you put it in app\libs for cake 1.x and in app\Lib for cake 2.x, if not it goes inside the app\vendors or app\Vendor.

To load it in a component for cake 2.x you would add before your component class declaration:

App::uses('MathLib', 'Lib');

The class name and file name should be the same.

For 1.x you would load it by:

App::import('Lib', 'MathLib');

More info for 1.x here http://book.cakephp.org/1.3/view/1579/Library-classes

If it's a vendor, same idea, but read these docs: http://book.cakephp.org/1.3/view/944/Vendor-examples.

It's the file naming that's important.

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