CakePHP is an MVC framework, which stands for model, view, and controller—a pattern which separates concerns regarding application code and data management. This training video explains the logical flow of CakePHP and how it implements the MVC pattern to render web requests.
- CakePHP is an MVC framework. MVC stands for model, view, and controller. It's a pattern for separating the concerns regarding both the code that makes up your application and the data you manage with that application. Model is the layer that talks directly to the database. This layer deals typically in processing and manipulating any data received from your database, as well as saving and validating data received from the end user. The roles about data live here.
View is the layer that presents the output of the application to the end user. This is the layer that generates the HTML, JSON, XML, or any other format that the browser will receive 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, does logic as needed on the data return from either the user or the model, and then tells the view to render this collection of data.
The core logical 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. This gets received by the first layer in Cake PHP, 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 the final webpage. As a high level overview, this is how CakePHP implements the MVC pattern to render web requests.
CakePHP is a critical framework for PHP developers. It helps them build complex web applications faster and more efficiently than coding by hand. If you want to use CakePHP 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 the framework. He shows how to use CakePHP shells and the console to build your first basic CakePHP app, and then discusses each application element in depth: controllers, models, views, components, behaviors, helpers, and utilities.
In later chapters the course gets a little more advanced. Watch these videos to learn how to write a custom shell, 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.
NOTE: While CakePHP 2 is a slightly older version of the framework, it's still an actively developed tool that is useful for maintaining and updating web applications. Many of the conventions and problem-solving approaches in this course are also applicable to CakePHP 3.
- Comparing CakePHP 2 and CakePHP 3
- Installing and configuring CakePHP
- Using different CakePHP shells
- Creating CakePHP controllers
- Saving data in a CakePHP model
- Creating views
- Using components to share functionality between controllers
- Using behaviors
- Formatting data with helpers
- Developing faster with CakePHP utilities
- Writing a custom CakePHP shell
- Creating a custom plugin
- Testing CakePHP applications
- Authorizing users of CakePHP applications