Hi!
I use Cake 2.1, and I would like to know what is the right way to deliver myself the classes that I build in order to use them wherever I want (in a Model, Controller class).
I know that there is the component for using in the context of a Controller, but what about the contxt of a Model ?
A particular case when I might need this is when creating a class that deals with moving uploaded files to predefined paths, depending of the model, or file type. I want to use it in the beforeSave() method of the model and then, finally, to save the path in a fied of the table on which the model is mapped…
The easiest way for me would be to use the bootstrap.php in order to load all I need, but I guess that is not exactly right, especially when there is a considerable number of classes..
If you have a generic piece of code that is thought to be shared between models its called a behavior. See http://book.cakephp.org/2.0/en/models/behaviors.html
Validation of the file upload should be done in a model too. We’ve wrote a FileUploadBehavior for that, that deals with file uploads and its possible errors but I can’t share this code. We might open source it.
And by the way, for storing files I can suggest you this nice library https://github.com/avalanche123/Imagine I’ve already used it and it works really good.
In the case of Imagine you would place the lib inside app/Vendor/Imagine.