CakePHP 3 is an Model View Controller framework. This tutorial explains the underlying MVC pattern and how CakePHP uses this pattern to achieve seperation of concerns. A Model View Controller pattern separates the code that makes up your application from the data you manage with the application. The model layer talks directly to the database. The view layer presents the output of the application to the end user. The controller layer joins the model and view together.
- [Voiceover] CakePHP as an MVC Framework. MVC stands for Model-View-Controller. MVC is a pattern for seperating concerns regarding the data of a system and the user interface for that same system. That definition is a little broad, but don't worry, we're going to explain it in more detail. The model layer is the layer that talks directly to the database layer. This layer deals typically in processing and manipulating any data recieved from the database, as well as saving and validating data received from the end user.
The rules about data live here. View is layer that presents the output of the application to the end user. This is the layer that generates the HTML, XML, or any other format that the browser will recieve and render. The presentation of data lives here. Controller is the layer that joins the model and view together. It processes requests from the user, to call the model layer as needed. It does logic as needed on the data return, from either the user or the model, and then tells the view to render that collection of data.
The chorological flow of our application lives here. Let's look at a normal web request to a CakePHP application. You hit a link, and tell the browser you want to go to myawesomeCakePHPsite.com. What happens on the CakePHP side? The client, that's our web browser, sends out an HTTP request with a bunch of information. That gets recieved by the first layer in CakePHP, the dispatcher. The dispatcher essentially makes decisions about what to do with this request. In essence, what controller to send the request to.
It builds up the basic CakePHP framework stack around the request, and then sends it off to the controller. The controller takes over here, and decides what methods to call on this request. The controller tells the model to retrieve data from the database, or to save new data to the database. The model then returns back to the controller, to manipulate the results of any database queries run. The controller then sets information for the view, and tells the view to render itself. The view layer then renders and creates the HTML to send to the client.
The client, our browser, then reads the HTML, and then renders the HTML as a final webpage. As a high level overview, this is how CakePHP implements the MVC pattern to render our web request. MVC follows the idea that in general, most problems involve first, receiving a request from the user, second, making any decisions about that request, third, communicating with the database to either retrieve or save information to the database, and then to respond back with a set of HTML that the browser will render, and the process starts all over when the user clicks a new link, or submits a form, or does anything on your site.
CakePHP is a critical framework for PHP developers. It helps them build complex web applications faster and more efficiently. If you want to use CakePHP 3 (the latest version of the framework) in your own development workflow, this is the place to start.
Justin Yost provides an overview of the underlying MVC pattern in CakePHP, and the installation and configuration process for Mac and Windows. He shows how to use the CakePHP shell to build your first basic CakePHP app, and then discusses each application element in depth: controllers, models, views, components, behaviors, helpers, and utilities. At each step, he discusses the relevant new features and enhancements in CakePHP 3, including new components; performance, session management, and ORM improvements; and localization.
In later chapters, the course gets a little more advanced. Watch these tutorials to learn how to send email with CakePHP, extend CakePHP with plugins, and write unit tests to identify and eliminate bugs in your code. Justin also shows how to add security to your CakePHP apps with a basic user authentication system.
- Installing and configuring CakePHP
- Using the CakePHP shell console
- Creating CakePHP controllers
- Saving data in a CakePHP model
- Finding and deleting data
- Working with entity methods
- Creating CakePHP views
- Using and customizing components to share functionality between controllers
- Creating behaviors
- Formatting data with helpers
- Developing faster with CakePHP utilities: hash, collections, and logging
- Sending CakePHP email
- Creating a custom plugin
- Testing CakePHP applications
- Authorizing users of CakePHP applications