I’m developing a simple app with a CRUD admin panel, using CodeIgniter. One of my models has 5 optional images, so when I create a new register, the app should check the amount of images the user has input, upload and store them properly.
Currently, the code that handles the uploading and the storage is in my controller. However, I’ve been reading a lot about MVC and some say that the controller should be as skinny as possible, so I’m wondering if it’d be a good idea to move that code to the model.
What do you think?
Well, yes in CI examples (user guide) file upload logic is placed in controllers, but i would prefer placing such codes in models. As per MVC, controllers can be considered the “middle man” of the application. It works with the user, taking in data, and then working with the model to get the appropriate data or calculation, and then working with the view to show the response to the user.
And models are responsible for holding functions and variables that are involved with whatever it’s representing, like functions to upload user’s images, get users info, images, etc.
So i prefer adding file upload code in models rather than controllers.