Chapter 6. Adapting to MVC
Web applications are more complex than what we have built so far. The more functionality you add, the more difficult the code is to maintain and understand. It is for this reason that structuring your code in an organized way is crucial. You could design your own structure, but as with OOP, there already exist some design patterns that try to solve this problem.
MVC (model-view-controller) has been the favorite pattern for web developers. It helps us separate the different parts of a web application, leaving the code easy to understand even for beginners. We will try to refactor our bookstore example to use the MVC pattern, and you will realize how quickly you can add new functionality after that.
In this chapter, you will learn the following:
- Using Composer to manage dependencies
- Designing a router for your application
- Organizing your code into models, views, and controllers
- Twig as the template engine
- Dependency injection