Core application components available on Yii framework


Yii predefines a set of core application components to provide features common among Web applications. For example, the request component is used to collect information about a user request and provide information such as the requested URL and cookies. By configuring the properties of these core components, we can change the default behavior of nearly every aspect of Yii. Here is a list the core components that are pre-declared by CWebApplication:

  • assetManager: CAssetManager – manages the publishing of private asset files.
  • authManager: CAuthManager – manages role-based access control (RBAC).
  • cache: CCache – provides data caching functionality. Note, you must specify the actual class (e.g.CMemCache, CDbCache).
  • Otherwise, null will be returned when you access this component.
  • clientScript: CClientScript – manages client scripts (javascript and CSS).
  • coreMessages: CPhpMessageSource – provides translated core messages used by the Yii framework.
  • db: CDbConnection – provides the database connection. Note, you must configure its connectionStringproperty in order to use this component.
  • errorHandler: CErrorHandler – handles uncaught PHP errors and exceptions.
  • format: CFormatter – formats data values for display purpose.
  • messages: CPhpMessageSource – provides translated messages used by the Yii application.
  • request: CHttpRequest – provides information related to user requests.
  • securityManager: CSecurityManager – provides security-related services, such as hashing and encryption.
  • session: CHttpSession – provides session-related functionality.
  • statePersister: CStatePersister – provides the mechanism for persisting global state.
  • urlManager: CUrlManager – provides URL parsing and creation functionality.
  • user: CWebUser – carries identity-related information about the current user.
  • themeManager: CThemeManager – manages themes.
Application Life Cycle of Yii framework

When handling a user request, an application will undergo the following life cycle:
1. Pre-initialize the application with CApplication::preinit();
2. Set up the class autoloader and error handling;
3. Register core application components;
4. Load application configuration;
5. Initialize the application with CApplication::init()
• Register application behaviors;
• Load static application components;
6. Raise an onBeginRequest event;
7. Process the user request:
• Collect information about the request;
• Create a controller;
• Run the controller;
8. Raise an onEndRequest event;

filter in Yii framework

Filter is a piece of code that is configured to be executed before and/or after a controller action executes. For example, an access control filter may be executed to ensure that the user is authenticated before executing the requested action; a performance filter may be used to measure the time spent executing the action.
An action can have multiple filters. The filters are executed in the order that they appear in the filter list. A filter can prevent the execution of the action and the rest of the unexecuted filters.
A filter can be defined as a controller class method. The method name must begin with filter. For example, a method named filterAccessControl defines a filter named accessControl. The filter method must have the right signature:

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: ,