The view is the part of a Model-View-Controller application that interacts with the end-users and that lays out the data retrieved by the controller on an HTML page. Even though its purpose is just writing some HTML code, if done wrong, a view can turn the application into a maintenance nightmare.
In this chapter you learn:
How to create a view
What the responsibilities of the view are
How to write HTML forms
How to extend a view
In the previous chapter you probably noticed that the MVC mantra about having a skinny controller and a fat model also includes an adjective for the view: dumb. This means that the view must not have business logic, but should only take the data it receives from the controller and insert it into the page's HTML. The only logic allowed inside the view is some conditional formatting or hiding/showing areas of the page based on certain conditions, but that should be all.
You already read this guideline in the previous chapter. We're stressing it here because it is a very important concept, which if not applied can make the use of MVC useless. But enough with theoretical concepts: The rest of the chapter is all about how to create a view and write HTML in it.
You already created some views in the examples in previous chapters, so you might already have guessed what the rules for creating a view might be. Now it's time to lay them down in detail.
Before diving deeply into the view, there is a part ...