Where do I put my classes in the MVC standard?

Asked

Viewed 125 times

1

I am writing a MVC application in PHP and the directory structure is as follows:

- root
    ¬ app
        ¬ controllers
        ¬ models
        ¬ views
    ¬ core
        ¬ config
    ¬ public
  • In the "app" folder is the MVC layers.
  • In "controllers" I place classes that will receive data and trigger models and/or render views.
  • In the "models" I place basically the entities of the database and their operations. In "views" I place the pages with html code + php to data display.
  • In "core" I put generic classes and/or files (I have plans for use this same basis to develop other applications in the future, a kind of microframework).

However, two different classes emerged, one of them works with dates and performs operations such as conversion and calculation between dates, the other creates and manages multiple threads. I have doubts in which layer I should put them, since none of them make access to database or files and neither emits outputs, only return values.

  1. Should I create an additional layer? Which?
  2. I must place it in one of the existing layers?

Obs: any additional information that may be useful is always welcome!

  • You can create a directory helper with generic codes that help in various parts of the application

  • 1

    There is the biggest error of articles and even some answers here of the site and other sites about IT, affirm to us things about MVC that are not true and surely soon will arrive one or more answers to you stating things like "the correct is X" or "the good practice says"... In addition, many people think that Model always refers to the database, many even write to model structures as being connections to databases and tables, then frameworks appear that follow certain OWN structures and people think that it is the right one and come out by promoting articles and responses [...]

  • 1

    [...] "the word" and the moment you ask to create a layer or not already shows that you "taught"well wrong what is MVC, vc can even use a MVC framework ready, but it will not mean that you are using MVC, because even in this structure a small difference of use can cause something to simply not be what was proposed, I’ll tell you 4 things:

  • 1

    FIRST: I went through the same doubts as you and I was also "taught wrong" - SECOND: MVC is not object oriented - THIRD: MVC came well before the Web and OOP - QUARTER: you can create a MVC with three or fewer pure PHP files, no OOP, no functions and with at most some logic instructions.

  • I’m sorry, but I’m still wondering :/

  • If you want to separate by responsibilities, it’s not the Controller that triggers the models. The Controller, which I prefer to call Resource is responsible for generating an http response from a request. All the logic behind this is implemented independently of the HTTP protocol. For example, my "controllers" usually have 5 lines, sometimes not even that.

  • 1

    If you could answer the questions on the topic and justify them I would be grateful, so I could reason on the answer and finally learn. :\

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.