Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Symfony Control layer

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you the example analysis of the Symfony control layer, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The details are as follows:

The control layer in Symfony contains code that connects business logic and presentation, and the control layer is divided into several different parts for different uses.

1. The front-end controller is the only entrance to the application

two。 The action contains the logic of the application, which checks the integrity of the request and prepares the data needed by the presentation layer

3. Request, response, and Session objects provide access request parameters, response parameters, and persistent user data, which are commonly used at the control layer

4. A filter is part of the code to be executed for each request, either before or after the action. You can create your own filter.

Front-end controller

All WEB requests will be captured by the front-end controller, which is the only entry point for the whole application in a given environment. The current control receives a request that uses the routing system to match the action name and module name of the URL entered by the user. For example:

Http://localhost/index.php/mymodule/myAction

URL calls the index.php script (that is, the front controller), which is understood as: action-myAction, module-mymodule

Working details of the front-end controller

The front-end controller distributes requests, and it only executes common and common code, including:

1. Define core constant

two。 Locate the symfony library

3. Load and initialize core framework classes

4. Load configuration information

5. Decode the request URL to get the action to be performed and the request parameters

6. If the action does not exist, the special 404 error

7. Activate the filter (for example, if authentication is required)

8. Execute the filter for the first time

9. Perform actions and submit views

10. Execute filter, second time

11. Output the response.

Default front controller

The default front controller is called index.php, which is a simple PHP file in the WEB/ directory of the project, as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 252

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report