123456789101112131415161718192021222324252627282930 |
- <?php
- namespace frontend\modules\api;
- use Yii;
- class Api extends \yii\base\Module
- {
- public $controllerNamespace = 'frontend\modules\api\controllers';
- public function init()
- {
- parent::init();
- $config = require(__DIR__ . '/config.php');
- // 获取应用程序的组件
- $components = \Yii::$app->getComponents();
- // 遍历子模块独立配置的组件部分,并继承应用程序的组件配置
- foreach ($config['components'] as $k => $component) {
- if (isset($component['class']) && !isset($components[$k])) continue;
- $config['components'][$k] = array_merge($components[$k], $component);
- }
- // 将新的配置设置到应用程序
- // 很多都是写 Yii::configure($this, $config),但是并不适用子模块,必须写 Yii::$app
- Yii::configure(Yii::$app, $config);
- //由于yii框架在之前已经注册过errorHandler,所以这里需要重新注册一下才能生效
- Yii::$app->errorHandler->register();
- // custom initialization code goes here
- }
- }
|