mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-21 10:57:08 +08:00
Update structure-modules.md
This commit is contained in:
@ -176,13 +176,13 @@ yii <module_id>/<command>/<sub_command>
|
|||||||
[[yii\base\Module::defaultRoute]] 属性来决定使用哪个控制器/操作,
|
[[yii\base\Module::defaultRoute]] 属性来决定使用哪个控制器/操作,
|
||||||
也就是说路由 `forum` 可能代表 `forum` 模块的 `default` 控制器。
|
也就是说路由 `forum` 可能代表 `forum` 模块的 `default` 控制器。
|
||||||
|
|
||||||
The URL manager rules for the modules should be added before [[yii\web\UrlManager::parseRequest()]] is fired. That means doing it
|
在 [[yii\web\UrlManager::parseRequest()]] 被触发之前应该添加模块 URL 管理器规则。
|
||||||
in module's `init()` won't work because module will be initialized when routes were already processed. Thus, the rules
|
这就意味着在模块的 `init()` 将不会起作用,因为模块将在路由开始处理时被初始化。
|
||||||
should be added at [bootstrap stage](structure-extensions.md#bootstrapping-classes). It is a also a good practice
|
因此应该在 [bootstrap stage](structure-extensions.md#bootstrapping-classes) 添加规则。
|
||||||
to wrap module's URL rules with [[\yii\web\GroupUrlRule]].
|
使用 [[\yii\web\GroupUrlRule]] 去实现模块的 URL 规则也是一种很好的做法。
|
||||||
|
|
||||||
In case a module is used to [version API](rest-versioning.md), its URL rules should be added directly in `urlManager`
|
如果一个模块用于 [version API](rest-versioning.md),
|
||||||
section of the application config.
|
它的 URL 规则应该直接添加到应用程序配置的 `urlManager` 中。
|
||||||
|
|
||||||
|
|
||||||
### 访问模块 <span id="accessing-modules"></span>
|
### 访问模块 <span id="accessing-modules"></span>
|
||||||
@ -279,13 +279,13 @@ class Module extends \yii\base\Module
|
|||||||
|
|
||||||
## Accessing components from within modules
|
## Accessing components from within modules
|
||||||
|
|
||||||
Since version 2.0.13 modules support [tree traversal](concept-service-locator.md#tree-traversal). This allows module
|
从 2.0.13 版本开始模块支持 [tree traversal](concept-service-locator.md#tree-traversal).
|
||||||
developers to reference (application) components via the service locator that is their module.
|
这允发模块开发人员通过作为其模块的服务定位器去引用(应用程序)组件。
|
||||||
This means that it is preferable to use `$module->get('db')` over `Yii::$app->get('db')`.
|
这意味着最好使用 `$module->get('db')` 而不是 `Yii::$app->get('db')`。
|
||||||
The user of a module is able to specify a specific component to be used for the module in case a different component
|
在需要不同组件(配置)的情况下,
|
||||||
(configuration) is required.
|
模块开发者能够指定要用于模块的特定组件。
|
||||||
|
|
||||||
For example consider partial this application configuration:
|
例如,以下是部分应用程序的配置:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
'components' => [
|
'components' => [
|
||||||
@ -307,8 +307,8 @@ For example consider partial this application configuration:
|
|||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
The application database tables will be prefixed with `main_`, while all module tables will be prefixed with `module_`.
|
应用程序数据表将会以 `main_` 作为前缀,而所有模块表都将以 `module_` 为前缀。
|
||||||
Note that configuration above is not merged; the modules' component for example will have the query cache enabled since that is the default value.
|
注意上面的配置并未合并;例如模块的组件都将启用查询缓存,因为这是默认的设置。
|
||||||
|
|
||||||
## 最佳实践 <span id="best-practices"></span>
|
## 最佳实践 <span id="best-practices"></span>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user