mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-18 03:21:18 +02:00
Added "Application Design Patterns" section.
This commit is contained in:
36
_posts/13-01-01-Application-Design-Patterns.md
Normal file
36
_posts/13-01-01-Application-Design-Patterns.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Application Design Patterns
|
||||
|
||||
There are numerous ways to structure your web applications, and you can put as much or as little thought as you like
|
||||
into architecting your code. But it is usually a good idea to follow to one of the common patterns because it will make
|
||||
your code easier to manage and easier for others to understand.
|
||||
|
||||
The most common patterns used in PHP development today are the front controller pattern and the MVC pattern (and its
|
||||
relatives).
|
||||
|
||||
* [Architectural patterns on Wikipedia](https://en.wikipedia.org/wiki/Architectural_pattern)
|
||||
* [Software design pattern on Wikipedia](https://en.wikipedia.org/wiki/Software_design_pattern)
|
||||
|
||||
## Front Controller
|
||||
|
||||
The front controller pattern is where you have a single entrance point for you web application (e.g. index.php) that
|
||||
handles all of the requests. This code is responsible for loading all of the dependencies, processing the request and
|
||||
sending the response to the browser. The front controller pattern can be beneficial because it encourages modular code
|
||||
and gives you a central place to hook in code that should be run for every request (such as input sanitization).
|
||||
|
||||
* [Front Controller pattern on Wikipedia](https://en.wikipedia.org/wiki/Front_Controller_pattern)
|
||||
|
||||
## Model-View-Controller
|
||||
|
||||
The model-view-controller (MVC) pattern and its relatives HMVC and MVVM let you break up code into logical objects that
|
||||
serve very specific purposes. Models serve as a data access layer where data it fetched and returned in formats usable
|
||||
throughout your application. Controllers handle the request, process the data returned from models and load views to
|
||||
send in the response. And views are display templates (markup, xml, etc) that are sent in the response to the web
|
||||
browser.
|
||||
|
||||
MVC is the most common pattern used in the popular [PHP frameworks](https://github.com/codeguy/php-the-right-way/wiki/Frameworks).
|
||||
|
||||
Learn more about MVC and its relatives:
|
||||
|
||||
* [MVC](https://en.wikipedia.org/wiki/Model%E2%80%93View%E2%80%93Controller)
|
||||
* [HMVC](https://en.wikipedia.org/wiki/Hierarchical_model%E2%80%93view%E2%80%93controller)
|
||||
* [MVVM](https://en.wikipedia.org/wiki/Model_View_ViewModel)
|
Reference in New Issue
Block a user