Commit 768f94f9 by Qiang Xue

Finished module guide [skip ci]

parent ffa596f5
......@@ -10,12 +10,15 @@ Each application component has an ID that uniquely identifies itself among other
in the same application. You can access an application component through the expression
```php
\Yii::$app->ComponentID
\Yii::$app->componentID
```
For example, you can use `\Yii::$app->db` to get the [[yii\db\Connection|DB connection]],
and `\Yii::$app->cache` to get the [[yii\caching\Cache|primary cache]] registered with the application.
An application component is created the first time it is accessed through the above expression. Any
further accesses will return the same component instance.
Application components can be any objects. You can register them by configuring
the [[yii\base\Application::components]] property in [application configurations](structure-applications.md#application-configurations).
For example,
......@@ -48,6 +51,29 @@ For example,
and use it when needed.
## Bootstrapping Components <a name="bootstrapping-components"></a>
As mentioned above, an application component will only be instantiated when it is being accessed the first time.
If it is not accessed at all during a request, it will not be instantiated. Sometimes, however, you may want
to instantiate an application component for every request, even if it is not explicitly accessed.
To do so, you may list its ID in the [[yii\base\Application::bootstrap|bootstrap]] property of the application.
For example, the following application configuration makes sure the `log` component is always loaded:
```php
[
'bootstrap' => [
'log',
],
'components' => [
'log' => [
// configuration for "log" component
],
],
]
```
## Core Application Components <a name="core-application-components"></a>
Yii defines a set of *core* application components with fixed IDs and default configurations. For example,
......
......@@ -89,7 +89,7 @@ use yii\helpers\HtmlPurifier;
Like [controllers](structure-controllers.md) and [models](structure-models.md), there are conventions to organize views.
* For views rendered in a controller, they should be put under the directory `@app/views/ControllerID` by default,
* For views rendered by a controller, they should be put under the directory `@app/views/ControllerID` by default,
where `ControllerID` refers to the [controller ID](structure-controllers.md#routes). For example, if
the controller class is `PostController`, the directory would be `@app/views/post`; If it is `PostCommentController`,
the directory would be `@app/views/post-comment`. In case the controller belongs to a module, the directory
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment