Guidelines for Implementing Models in the MVC Template

What are the best methods for implementing models in an MVC pattern. In particular, if I have "Users", I need to implement 2 classes. One for managing all users and one for managing one user. So something like "Users" and "User"?

I am writing a Zend Framework application in php, but this is a more general question.

+4
source share
3 answers

The model should be determined by the needs of the problem. Therefore, if you need to handle multiple users, then a class representing a collection of users might be appropriate, yes. However, if you do not need it, do not write! You may find that a simple array of User objects is sufficient for your purposes.

+6
source

This will be the application and implementation of MVC. You can define a class that collects logically related classes, or you can define a static register in a user class. This is more a matter of OO than MVC.

0
source

I will be the second Giraffe, saying that using included collections is almost always better than trying to write your own.

But I think your original question can be changed a little differently ... "Do I need a separate class to manage users other than the User class?

I use the static factory class to collect all my users and save them back to the database again. I believe that your model classes should be as deep as possible and that you use heavy controller classes to do all the work for the model classes.

0
source

All Articles