main.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. $params = array_merge(
  3. require(__DIR__ . '/../../common/config/params.php'),
  4. require(__DIR__ . '/params.php'),
  5. require(__DIR__ . '/params-local.php')
  6. );
  7. return [
  8. 'id' => 'api',
  9. 'basePath' => dirname(__DIR__),
  10. 'controllerNamespace' => 'api\common\controllers',
  11. 'components' => [
  12. 'user' => [
  13. 'identityClass' => 'api\common\models\User',
  14. ],
  15. 'urlManager' => [
  16. 'enablePrettyUrl' => true,
  17. 'enableStrictParsing' => true,//严格url管理,增强接口安全性
  18. 'showScriptName' => false,
  19. 'rules' => [
  20. [
  21. 'class' => 'yii\rest\UrlRule',
  22. 'pluralize' => false,//关闭路由自动复数,减少开发成本
  23. 'controller' => [
  24. 'v1/carousel',
  25. 'v1/category',
  26. 'v1/tag',
  27. 'v1/comment',
  28. 'v1/suggest',
  29. ]
  30. ],
  31. [
  32. 'class' => 'yii\rest\UrlRule',
  33. 'pluralize' => false,
  34. 'controller' => 'v1/article',
  35. 'extraPatterns' => [
  36. 'GET count' => 'count',
  37. 'GET footprint' => 'footprint',
  38. 'GET module' => 'module',
  39. 'GET history-search' => 'history-search',
  40. 'POST clear-search' => 'clear-search',
  41. ],
  42. ],
  43. [
  44. 'class' => 'yii\rest\UrlRule',
  45. 'pluralize' => false,
  46. 'controller' => 'v1/auth',
  47. 'extraPatterns' => [
  48. 'POST login' => 'login',
  49. 'POST login-by-id' => 'login-by-id',
  50. 'POST logout' => 'logout',
  51. 'POST bind-tel' => 'bind-tel',
  52. ],
  53. ],
  54. [
  55. 'class' => 'yii\rest\UrlRule',
  56. 'pluralize' => false,
  57. 'controller' => 'v1/user',
  58. 'extraPatterns' => [
  59. 'GET refresh' => 'refresh',
  60. 'POST set-chain' => 'set-chain',
  61. ],
  62. ],
  63. [
  64. 'class' => 'yii\rest\UrlRule',
  65. 'pluralize' => false,
  66. 'controller' => 'v1/common',
  67. 'extraPatterns' => [
  68. 'GET page' => 'page',
  69. 'GET config' => 'config',
  70. 'POST upload' => 'upload',
  71. 'GET version' => 'version',
  72. ],
  73. ],
  74. [
  75. 'class' => 'yii\rest\UrlRule',
  76. 'pluralize' => false,
  77. 'controller' => 'v1/survey',
  78. 'extraPatterns' => [
  79. 'GET survey' => 'survey',
  80. 'GET captcha' => 'captcha',
  81. 'POST submit' => 'submit',
  82. 'POST enterprise' => 'enterprise',
  83. ],
  84. ],
  85. [
  86. 'class' => 'yii\rest\UrlRule',
  87. 'pluralize' => false,
  88. 'controller' => 'v1/policy',
  89. 'extraPatterns' => [
  90. 'GET policy' => 'policy',
  91. 'GET category' => 'category',
  92. 'GET details' => 'details',
  93. ],
  94. ]
  95. ],
  96. ],
  97. 'request' => [
  98. 'enableCookieValidation' => false,
  99. 'parsers' => [
  100. 'application/json' => 'yii\web\JsonParser',//解析json请求
  101. ]
  102. ],
  103. ],
  104. 'modules' => [
  105. 'v1' => [
  106. 'class' => '\api\modules\v1\Module'
  107. ]
  108. ],
  109. 'params' => $params
  110. ];