Answer the question
In order to leave comments, you need to log in
Where in the MVC pattern to display headers and include sessions?
Hello. Where in MVC to display headers and connect sessions (session_start, etc.)? In which class, View or Controller?
Or how to implement this at all?
Just yesterday I sat down to study MVC, don't throw your shoes too hard in my direction))
Answer the question
In order to leave comments, you need to log in
Sessions and headers work in controllers or helper classes that the controller uses.
Why - because sessions and headers are a matter of how to process a request from a user, and controllers do just that. To make it easier to understand why this is so, imagine that controllers work not only with an HTTP request, but can also be used to process console commands where your headers and sessions are not needed at all. There will be many problems if you implement session work in the model layer, at a level where you cannot easily and simply (and without crutches) understand whether it was a console command or a request from a browser.
Important: don't try to see each class as a model, view, or controller. MVC tells us about layers, not concrete classes.
MVC describes the core of an application, but not every element of it .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question