0

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]
1
  • So, to clarify, the Document class represents documents held in the in the database via ORM? The Report class represents temporary data used to generate a report but is not persisted? Also, why do you think CustomTagFilter is a model class?
    – redbirdo
    May 10, 2013 at 9:31

3 Answers 3

1

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).

1

ORMs are working with Entites, which are basically the instances of the model classes (in your case Document.php), so calling your folder Entities would be logical.

To get a proper definition of Entity, dive into the documentation of the ORM you are using. (Here is an example from the documentation of Doctrine.)

4
  • /entities/report.php sound a bit strange when you think what an entity should be.
    – johnlemon
    May 7, 2013 at 8:50
  • Ok, so what I would do is put the ORM generated entities in /Entities/ or /Models/Entities/ folder, and the models created by you (if I understand correctly report.php is one like this) can be put in /Models/ or maybe /ViewModels/ folder. May 7, 2013 at 11:57
  • But isn't the term entities coming from DDD? In pure MVC is the entities folder a valid name conventation?
    – johnlemon
    May 7, 2013 at 12:02
  • I'm not quite sure about this, maybe someone more enlightened can clarify this. However I always met the phrase Entity in context of ORMs. And I think using an ORM adds a new layer to your app anyway, which helps the separation of concerns, and I guess this is your ultimate goal after all. May 7, 2013 at 13:26
0

I'd go with Transformers if I was in a whimsical mood:

/Models/Transformers/Reports.php
/Models/Transformers/CustomTagFilter.php

or Translators if I was feeling more business-like:

/Models/Translators/Reports.php
/Models/Translators/CustomTagFilter.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.