web.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. $params = require __DIR__ . '/params.php';
  3. $rsparams['params'] = require_config('ueditor.php');
  4. $rsparams = array_merge_recursive(require_config('coin.php'), $rsparams);
  5. $rsparams = array_merge_recursive(require_config('commission.php'), $rsparams);
  6. $rsparams = array_merge_recursive(require_config('mailer.php'), $rsparams);
  7. $rsparams = array_merge_recursive(require_config('mapp.php'), $rsparams);
  8. $rsparams = array_merge_recursive(require_config('mp.php'), $rsparams);
  9. $rsparams = array_merge_recursive(require_config('openauth.php'), $rsparams);
  10. $rsparams = array_merge_recursive(require_config('openwx.php'), $rsparams);
  11. $rsparams = array_merge_recursive(require_config('oss.php'), $rsparams);
  12. $rsparams = array_merge_recursive(require_config('pay.php'), $rsparams);
  13. $rsparams = array_merge_recursive(require_config('point.php'), $rsparams);
  14. $params = array_merge($params,$rsparams['params']);
  15. $db = require __DIR__ . '/db.php';
  16. $modulesConfig = require __DIR__ . '/modules.php';
  17. //区分前后台的URL重写规则
  18. if(defined('IN_ADMIN')&&IN_ADMIN==true)
  19. {
  20. $urlManager = [];
  21. }
  22. else
  23. {
  24. $rules = $params['htmlrule']?require __DIR__ . '/rules_html.php':require __DIR__ . '/rules.php';
  25. //生成手机站路由规则
  26. $mobRules = [];
  27. if(defined('IN_WAP')&&IN_WAP==true)
  28. {
  29. foreach($rules as $k=>$v)
  30. {
  31. $mobRules[WAP_URL.ltrim($k,"/")] = $v;
  32. }
  33. }
  34. //加载模块重写规则
  35. $modulePath = BASE_PATH.'modules/';
  36. $modules = dir_child($modulePath);
  37. if(is_array($modules))
  38. {
  39. foreach($modules as $moduleUnit)
  40. {
  41. $moduleRuleFile = $modulePath.$moduleUnit.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'rules.php';
  42. if(file_exists($moduleRuleFile))
  43. {
  44. $moduleRule = require $moduleRuleFile;
  45. $rules = array_merge($rules,$moduleRule);
  46. }
  47. }
  48. }
  49. $path_url = explode('?',get_url());
  50. $pathext = pathinfo(str_replace(APP_URL,'',$path_url[0]), PATHINFO_EXTENSION);
  51. $urlManager = [
  52. 'enablePrettyUrl' => true,
  53. 'showScriptName' => false,
  54. 'enableStrictParsing' => false,
  55. 'suffix' => in_array($pathext,['jpg'])?'':'/',
  56. 'rules' => array_merge($mobRules,$rules),
  57. ];
  58. }
  59. $config = [
  60. 'id' => 'web',
  61. 'language'=>$params['language'],
  62. 'bootstrap' => ['log'],
  63. 'aliases' => [
  64. '@bower' => '@vendor/bower-asset',
  65. '@npm' => '@vendor/npm-asset',
  66. ],
  67. 'defaultRoute' => 'site/index',
  68. 'components' => [
  69. 'user' => [
  70. 'identityClass' => 'app\models\User',
  71. 'enableAutoLogin' => true,
  72. 'enableSession'=>false,
  73. ],
  74. //请求
  75. 'request' => [
  76. // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
  77. 'cookieValidationKey' => $params['cookieValidationKey'],
  78. ],
  79. //缓存
  80. 'cache' => [
  81. 'class' => 'yii\caching\FileCache',
  82. ],
  83. //定义错误处理
  84. 'errorHandler' => [
  85. 'errorAction' => 'alert/error',
  86. ],
  87. 'mailer' => [
  88. 'class' => 'yii\swiftmailer\Mailer',
  89. 'viewPath' => BASE_PATH.'mail',
  90. // send all mails to a file by default. You have to set
  91. // 'useFileTransport' to false and configure a transport
  92. // for the mailer to send real emails.
  93. 'useFileTransport' => false,
  94. 'transport' => [
  95. 'class' => 'Swift_SmtpTransport',
  96. 'host' => $params['mailer']['host'],
  97. 'username' => $params['mailer']['username'],
  98. 'password' => $params['mailer']['password'],
  99. 'port' => $params['mailer']['port'],
  100. 'encryption' => $params['mailer']['encryption'],
  101. ],
  102. 'messageConfig'=>[
  103. 'charset'=>'UTF-8',
  104. 'from'=>[$params['mailer']['fromname']=>$params['mailer']['fromtitle']]
  105. ],
  106. ],
  107. //日志
  108. 'log' => [
  109. 'traceLevel' => YII_DEBUG ? 3 : 0,
  110. 'targets' => [
  111. [
  112. 'class' => 'yii\log\FileTarget',
  113. 'levels' => ['error', 'warning'],
  114. ],
  115. [
  116. 'class' => 'yii\log\FileTarget',
  117. 'categories' => ['collect'],
  118. 'levels' => ['error', 'warning'],
  119. 'logVars' => ['*'], // 只记录message
  120. 'logFile' => '@runtime/logs/collect.log',
  121. ],
  122. ],
  123. ],
  124. 'urlManager' => $urlManager,
  125. //多语言设置
  126. 'i18n' => [
  127. 'translations' => [
  128. 'admin' => [
  129. 'class' => 'yii\i18n\PhpMessageSource',
  130. 'basePath' => '@app/messages',
  131. ],
  132. 'attr' => [
  133. 'class' => 'yii\i18n\PhpMessageSource',
  134. 'basePath' => '@app/messages',
  135. ],
  136. 'resource' => [
  137. 'class' => 'yii\i18n\PhpMessageSource',
  138. 'basePath' => '@app/messages',
  139. ],
  140. 'error' => [
  141. 'class' => 'yii\i18n\PhpMessageSource',
  142. 'basePath' => '@app/messages',
  143. ],
  144. ],
  145. ],
  146. //清除资源缓存
  147. 'assetManager' => [
  148. 'appendTimestamp' => YII_DEBUG==true?true:false,
  149. 'bundles'=>[
  150. 'yii\web\JqueryAsset'=>[
  151. 'sourcePath' => null,
  152. 'js' => []
  153. //'jsOptions'=>['position'=>\yii\web\View::POS_HEAD]
  154. ]
  155. ]
  156. ],
  157. /*REDIS配置(用于负载均衡配置)*/
  158. /*'session'=>[
  159. 'class' => 'yii\redis\Session',
  160. 'keyPrefix'=>'session', // 跨站共享session,前缀必须设置一样
  161. 'redis' => 'redis',
  162. ],
  163. 'redis' => [
  164. 'class' => 'yii\redis\Connection',
  165. 'hostname' => '101.133.111.222', // Redis服务器 IP
  166. 'port' => 6379, // Redis 端口
  167. 'database' => 0,
  168. ],*/
  169. ],
  170. 'params' => $params,
  171. 'modules' => $modulesConfig,
  172. ];
  173. $config['components'] = array_merge($config['components'],$db);
  174. if (YII_ENV_DEV) {
  175. // configuration adjustments for 'dev' environment
  176. /* $config['bootstrap'][] = 'debug';
  177. $config['modules']['debug'] = [
  178. 'class' => 'yii\debug\Module',
  179. // uncomment the following to add your IP if you are not connecting from localhost.
  180. //'allowedIPs' => ['127.0.0.1', '::1'],
  181. ];*/
  182. $config['bootstrap'][] = 'gii';
  183. $config['modules']['gii'] = [
  184. 'class' => 'yii\gii\Module',
  185. // uncomment the following to add your IP if you are not connecting from localhost.
  186. //'allowedIPs' => ['127.0.0.1', '::1'],
  187. ];
  188. }
  189. return $config;