Ricardo clicked the link pointing to http://www.example.com/cakes/buy, and the browser sent a request to your web server. A typical CakePHP request
We have covered the basic elements in CakePHP. let's see how objects work together to complete a basic request. The following is an example of the original request. let's imagine our friend Ricardo just clicked "Buy A Custom Cake Now!" on the login page of the CakePHP application !" Link.
The flowchart shows a standard CakePHP request.
Number: 2. standard CakePHP request.
Black = essential elements, gray = optional elements, blue = callback
- Ricardo clicked a link pointing to the http://www.example.com/cakes/buy and its browser sent a request to your web server.
- This URL is used to obtain the parameters in the request: Controller, action, and all the remaining parameters that affect the business logic in the request.
- Using routing, the request URL is mapped to a controller action (a method of a specific controller class ). In this example, it is the bug () method of CakesController. The beforeFilter callback method of this controller will be called before all its logical actions are executed.
- The controller may use the model to obtain application data. In this example, the controller uses the model to match the last order of Ricardo from the database. All available model callbacks, behaviors, and data sources will be applied in this operation. The model is not mandatory, but all CakePHP controllers initialize at least one model.
- When the model obtains the data, it returns it to the controller, and the model callback is applied.
- The controller may use components to further improve data or perform other operations (such as session processing, permissions, or email sending ).
- Once the controller has prepared data using models and components, the data is transmitted to the view using the set () method of the controller. Controller callback may be called before data transmission. View logic is executed, which may include elements and/or assistants. By default, a view is rendered in a layout.
- Additional controller reconciliation (such as afterFilter) may be applied. After everything is done, the rendered view code is transferred to Ricardo's browser.