Just tinkering around with MVC in PHP for the first time. I’m following a simple tutorial where I’ve stumbled upon a problem which isn’t mentioned in the current tutorial: What is the correct way to include global files (such as header and footer) within the MVC principles if I want to include some special functions for each page (inside the header and/or footer)?
Say I’ve got a “log page” and a “home page” which both includes the footer.php. However on the “log page” I want some additional text in the footer (to keep it simple). Making separate files is one solution but that feels awkward and also breaks the MVC principle in my mind.
Another solution is perhaps to pass the $_REQUEST from the controller which determines what view should be loaded into the footer – but that again seems to break up the MVC as this, in my mind, is application logic?
The third solution which I’m starting to believe is the best (keep in mind I’m learning!) is to pass data from the model via the controller to the footer and header in the same way I do for page views, thus making header and footer views in their own.
What you need is called Layout in MVC and yes, it’s a view. Here is a relevant question with an answer: View in MVC, what is a layout and how to create one