'api', 'controllerNamespace' => 'api\controllers', 'language'=>$params['language'], 'bootstrap' => ['log'], //'defaultRoute'=>'user',//设置默认的控制器 'aliases' => [ '@api' => '@app/api', ], 'components' => [ 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => $params['cookieValidationKey'], ], 'cache' => [ 'class' => 'yii\caching\FileCache', ], 'user' => [ 'identityClass' => 'app\modules\ucenter\models\User', 'enableAutoLogin' => true, 'enableSession'=>false, ], //定义错误处理 'errorHandler' => [ 'errorAction' => 'alert/error', ], 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => BASE_PATH.'mail', // send all mails to a file by default. You have to set // 'useFileTransport' to false and configure a transport // for the mailer to send real emails. 'useFileTransport' => false, 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => $params['mailer']['host'], 'username' => $params['mailer']['username'], 'password' => $params['mailer']['password'], 'port' => $params['mailer']['port'], 'encryption' => $params['mailer']['encryption'], ], 'messageConfig'=>[ 'charset'=>'UTF-8', 'from'=>[$params['mailer']['fromname']=>$params['mailer']['fromtitle']] ], ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'response' => [ 'class' => 'yii\web\Response', 'on beforeSend' => function ($event) { $response = $event -> sender; $resdata = $response -> data; if ($response->data !== null && !isset($resdata['error'])) { $resdata['message'] = str_replace("Your request was made with invalid credentials.","接口凭证已失效,请刷新页面后重试",$resdata['message']); $response -> data = [ 'error' => $resdata['status'], 'msg' => $resdata['message'], 'data' => [ 'name' => $resdata['name'], 'code' => $resdata['code'], 'type' => $resdata['type'], ], ]; $response -> statusCode = 200; } $response->format = yii\web\Response::FORMAT_JSON; }, ], 'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => false, 'showScriptName' => false, 'rules' => [ ['class' => 'yii\rest\UrlRule', 'controller' => 'alert', 'pluralize' => false, 'extraPatterns'=>[ 'GET error'=>'error', ], ], ['class' => 'yii\rest\UrlRule', 'controller' => 'default', 'pluralize' => false, 'extraPatterns'=>[ 'GET imgcode'=>'imgcode', 'POST setfield'=>'setfield', 'GET test'=>'test', ], ], ], ], //多语言设置 'i18n' => [ 'translations' => [ 'admin' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@app/messages', ], 'attr' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@app/messages', ], 'error' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@app/messages', ], ], ], ], 'params' => $params, 'modules' =>$modulesConfig, ]; $config['components'] = array_merge($config['components'],$db); if (YII_ENV_DEV) { // configuration adjustments for 'dev' environment $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = [ 'class' => 'yii\debug\Module', // uncomment the following to add your IP if you are not connecting from localhost. //'allowedIPs' => ['127.0.0.1', '::1'], ]; $config['bootstrap'][] = 'gii'; $config['modules']['gii'] = [ 'class' => 'yii\gii\Module', // uncomment the following to add your IP if you are not connecting from localhost. //'allowedIPs' => ['127.0.0.1', '::1'], ]; } return $config;