PHP/MVC – Structuring Models in PHP MVC Framework

mvcPHP

I have some classes that are composed with ORM generated Models.

example1:
For example the Report.php (Model) is using a Document.php Model generated with ORM. Based on the document object a report is created.

I would like to know some name suggestions for the Report.php folder path.
It clearly belongs to the /Model folder but in what subfolder?

example2:
The CustomTagFilter.php will remove some html tags from a html string.

I wish to find a clear path name for this kind of Models. Any suggestions ?

/Models/[SUGGESTION]

Best Answer

There are no rules on how you should organise your model code. Mostly not because it all depends on your application. At best, we can give you some food for thought.

In a small application (up to a few dozen model classes), I might not even bother with organising them in separate folders.

If a more structured organisation of the model classes is deemed beneficial, I would first group the classes according to functionality, so all the ORM related classes together, the classes dealing with functionality A together, etc. If still more organisation is needed, add another layer using whatever division seems right at that point.
For the posted examples, the division would probably come to

  • Models/
    • ORM/
      • Document.php
    • Filters/
      • CustomTagFilter.php
    • Report.php

The only thing to avoid is to use catch-all categories. If you can't think of a good category name, don't put it in a sub-category at all (like I did with Report.php).