O'Reilly logo

Mastering Yii by Charles R. Portwood II

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Components and objects

There are two base classes that almost everything in Yii2 extends from: the Component class and the Object class.

Components

In Yii2, the Component class has replaced the CComponent class from Yii1. In Yii1, components act as service locators that host a specific set of application components that provide different services for the processing of requests. Each component in Yii2 can be accessed using the following syntax:

Yii::$app->componentID

For example, the database component can be accessed using this:

Yii::$app->db

The cache component can be accessed using this:

Yii::$app->cache

Yii2 automatically registers each component at runtime via the application configuration that we mentioned in the previous section by name.

To improve ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required