Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
201

■ ■ ■


CHAPTER 14


MVC Architecture


Model-View-Controller (MVC) is a design pattern that simplifies application development
and maintenance. It achieves this by separating the application into three logical components:

Model: The model layer is responsible for the business logic of an application. It will encapsu-
late access to data stores and will provide a reusable class library. Typically, within the model,
you will find facilities for database abstraction, e-mail delivery, validation, and authentication.

View: The view layer is typically what would be considered web design, or templating.
It controls the look and feel of data and provides facilities to collect data from the user.
Technologies exclusively found in the view are HTML, CSS, and JavaScript.

Controller: The controller layer glues everything together and merges the styling of the
view with the functionality of the model. It is responsible for collecting input data from the
view and deciding program execution. The controller will call model facilities and inter-
pret the returning data so that it can be rendered by the view. It is also responsible for all
application exception and flow control.

This chapter introduces the MVC pattern and its advantages. In the final section, you will
create a minimal MVC framework to see how such a framework actually works.

Why Use MVC?


You might be wondering why MVC is so popular within web application development. While
there are many compelling reasons to use an MVC framework—from cleanliness of code to
ease of upgrading—the number one reason companies choose MVC development is the devel-
opment workflow that it encourages.

McArthur_819-9C14.fm Page 201 Thursday, February 28, 2008 7:44 AM

Free download pdf