web.php 7.0 KB

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