true, 'showScriptName' => false, 'enableStrictParsing' => false, 'rules' => [ ], ]; } else { $rules = $params['htmlrule']?require __DIR__ . '/rules_html.php':require __DIR__ . '/rules.php'; //生成手机站路由规则 $mobRules = []; if(defined('IN_WAP')&&IN_WAP==true) { foreach($rules as $k=>$v) { $mobRules[WAP_URL.ltrim($k,"/")] = $v; } } //加载模块重写规则 $modulePath = BASE_PATH.'modules/'; $modules = dir_child($modulePath); if(is_array($modules)) { foreach($modules as $moduleUnit) { $moduleRuleFile = $modulePath.$moduleUnit.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'rules.php'; if(file_exists($moduleRuleFile)) { $moduleRule = require $moduleRuleFile; $rules = array_merge($rules,$moduleRule); } } } $path_url = explode('?',get_url()); $pathext = pathinfo(str_replace(APP_URL,'',$path_url[0]), PATHINFO_EXTENSION); $urlManager = [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'enableStrictParsing' => false, 'suffix' => in_array($pathext,['jpg'])?'':'/', 'rules' => array_merge($mobRules,$rules), ]; } $config = [ 'id' => 'web', 'language'=>$params['language'], 'bootstrap' => ['log'], 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'defaultRoute' => 'site/index', 'components' => [ 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true, 'enableSession'=>false, ], //请求 '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', ], //定义错误处理 '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'], ], [ 'class' => 'yii\log\FileTarget', 'categories' => ['collect'], 'levels' => ['error', 'warning'], 'logVars' => ['*'], // 只记录message 'logFile' => '@runtime/logs/collect.log', ], ], ], 'urlManager' => $urlManager, //多语言设置 'i18n' => [ 'translations' => [ 'admin' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@app/messages', ], 'attr' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@app/messages', ], 'resource' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@app/messages', ], 'error' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@app/messages', ], ], ], //清除资源缓存 'assetManager' => [ 'appendTimestamp' => YII_DEBUG==true?true:false, 'bundles'=>[ 'yii\web\JqueryAsset'=>[ 'sourcePath' => null, 'js' => [] //'jsOptions'=>['position'=>\yii\web\View::POS_HEAD] ] ] ], /*REDIS配置(用于负载均衡配置)*/ /*'session'=>[ 'class' => 'yii\redis\Session', 'keyPrefix'=>'session', // 跨站共享session,前缀必须设置一样 'redis' => 'redis', ], 'redis' => [ 'class' => 'yii\redis\Connection', 'hostname' => '101.133.111.222', // Redis服务器 IP 'port' => 6379, // Redis 端口 'database' => 0, ],*/ ], '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;