I'm just starting out using programming using the MVC design pattern, and I would like to know if I understood it correctly and where I should put certain things.
So I understood that I should put all my files in one out of three folders, (or just separate the code):
Model - Database models.
Controllers - logic that deals with moving the info stored in the models to the view and the other way around.
View - Logic for displaying things to the user.
So my question is if I have some functions that help me deal with models, but isn't a model itself, where should I put it?
For example, let's say I have the next models: User, Post, Comment. And I created a function called "Add", and it receives the two arguments: "model name" and "properties" for that model, and the function uses the requested model and doest all the work needed to add it to the database.
And is there any good structural pattern you think I should get a look at?
EDIT: I saw that both answers I received are conflicting, so here I have a better example.
Let's say I have different types of "entries", they can be Articles, Blogs, a Video, etc... I already have a model for each one of them with the right relations between them and their comments, and the other things.
All those entries, share a common "basic structure", and they can be dynamically created.
So I created a function to help me manage those entries, and it receives the name of the entry, and the properties to be saved to the database., then that function sends that data to the appropriate model.
Here is the pseudo code representing the function:
function add( modelName, properties ) {
// Checking the inputs.
// Checking if a model with that model name exists
// Pass the properties to the right model
// Try to save it to the database
// Return errors/updates.
}
EDIT: I'm sorry I update with so many questions, it's just the best way I know for understanding stuff :)
So another question: Where is the right place for validating user input? should it go to the model?
And where do I check permissions of the user to access information?
If I understand correctly most of the logic goes into the Model?
And one last thing, I'm not familiar with most of the terminology of the MVC so please explain to me as simple as possible.