模块入口
<?php
namespace app\modules\api;
use yii\base\Module;
use yii;
class ApiModule extends Module
{
public function init()
{
parent::init();
yii::$app->response->format = yii\web\Response::FORMAT_JSON;
yii::configure($this, require(__DIR__ . '/config/main.php'));
}
}
模块控制器
<?php
namespace app\modules\api\controllers;
use yii;
use yii\web\Controller;
class IndexController extends Controller
{
public function actionIndex()
{
return (array) yii::$app->params;
}
}
模块的配置
<?php
return [
'components' => [
],
'params' => [
'id' => 5
]
];
为什么 yii::configure 没有生效,yii::$app->params
打印出来 是父级的值
先获取模块实例再访问模块配置!
模块的配置你用应用实例去获取当然获取不到
同问,我遇到了模块自定义配置不能生效的问题