Content of the «Handling Requests» section:
- Request Handling Overview
- Routing and URL Creation
- Sessions and Cookies
- Handling Errors
Articles section «Handling Requests»:
Yii provides a powerful logging framework that is highly customizable and extensible. Using this framework, you can easily log various types of messages, filter them, and gather them at different targets, such as files, databases, emails.
Using the Yii logging framework involves the following steps:
Yii includes a built-in [[yii\web\ErrorHandler|error handler]] which makes error handling a much more pleasant experience than before. In particular, the Yii error handler does the following to improve error handling:
- All non-fatal PHP errors (e.g. warnings, notices) are converted into catchable exceptions.
- Exceptions and fatal PHP errors are displayed with detailed call stack information and source code lines in debug mode.
- Supports using a dedicated controller action to display errors.
- Supports different error response formats.
Sessions and Cookies
Sessions and cookies allow data to be persisted across multiple user requests. In plain PHP you may access them through the global variables
$_COOKIE, respectively. Yii encapsulates sessions and cookies as objects and thus allows you to access them in an object-oriented fashion with additional useful enhancements.
When an application finishes handling a request, it generates a [[yii\web\Response|response]] object and sends it to the end user. The response object contains information such as the HTTP status code, HTTP headers and body. The ultimate goal of Web application development is essentially to build such response objects upon various requests.
Requests made to an application are represented in terms of [[yii\web\Request]] objects which provide information such as request parameters, HTTP headers, cookies, etc. For a given request, you can get access to the corresponding request object via the
request application component which is an instance of [[yii\web\Request]], by default. In this section, we will describe how you can make use of this component in your applications.
Routing and URL Creation
When a Yii application starts processing a requested URL, the first step it takes is to parse the URL into a route. The route is then used to instantiate the corresponding controller action to handle the request. This whole process is called routing.
The reverse process of routing is called URL creation, which creates a URL from a given route and the associated query parameters. When the created URL is later requested, the routing process can resolve it back into the original route and query parameters.
Page 1 of 2