View
The View represents the visual output that the application provides in response to a particular request. In most modern frameworks, the View layer includes a templating language that is designed to be frontend-developer-friendly, optimized for working on HTML and outputting safely escaped data. For the toy, we are sticking with plain PHP, though I have included a simple output escaping system.
The first thing that our app has to do is prepare the template data. I have kept the template data as a separate DTO, which is a pattern I encourage as it really helps to keep things organized. All template data implements a specific interface. Actually, the interface has no behavior in the toy – that is not an issue – but it does give us the option of enforcing standardized behavior later on, should we choose to.
What is a DTO again?
DTO stands for Data Transfer Object. It is simply an object that has no behavior and whose sole purpose is to be instantiated with data...