How coarse grainy should the MVC be?

I read several previously asked questions, and I did not meet the one that answers my question in "black and white" for me! So apologize if this is repeated. The question is probably similar to the question: β€œhow long is a piece of string”, but carrying with me!

For the registration system, I have a user model with features such as:

  • add_user
  • delete_user
  • activate_user

The above user model deals with a single table. The table of users in the MySQL database.

You can guess what each function does, but is it rude enough? I mean, if there were methods in my model that are much wider, for example:

  • add_record
  • delete_record
  • update_record

Where do I go to the table and the unique identifier of the record to delete, add or update?

I use codeigniter, but I'm interested in how everything should be done in a clean MVC environment.

Sorry if this question is too picky.

Thank you all

+6
php frameworks model-view-controller codeigniter
source share
2 answers

I'm not sure what you mean by "rude".

"if my model contains methods that are much wider, such as: add_record, delete_record, update_record"

Absolutely not. Never. This strikes the goal of having a model.

This type of "general purpose" is a database. The point of the model is to adapt the common database to your specific problem.

Your model should be specific to your problem.

"with functions like: add_user, delete_user, activate_user" This is the point. Your model reflects your application, your problem domain, your decision.

Your model should be able - in essence - autonomous. You should be able to wrap your model in a command line application or GUI or web page.

+10
source share

You can guess what each function does, but it's rude enough. I mean, should my model contain methods that are much wider, for example:

* add_record * delete_record * update_record 

Where do I go to the table and the unique identifier of the deleted record, add or update?

If you need to get only user information, it is not necessary to use the whole record, then it will be convenient for you to have *_user functions, but to include it only in your user model.

If you need to get entire records, not just the user, then it will also be convenient for you to have *_record functions, but put them in your recording model - NOT in your user model.

Here you need to remember not to include all these functions in only one model. Simply put, your user is the same as the post.

0
source share

All Articles