main.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. ],
  61. ],
  62. [
  63. 'class' => 'yii\rest\UrlRule',
  64. 'pluralize' => false,
  65. 'controller' => 'v1/common',
  66. 'extraPatterns' => [
  67. 'GET page' => 'page',
  68. 'GET config' => 'config',
  69. 'POST upload' => 'upload',
  70. 'GET version' => 'version',
  71. ],
  72. ],
  73. [
  74. 'class' => 'yii\rest\UrlRule',
  75. 'pluralize' => false,
  76. 'controller' => 'v1/survey',
  77. 'extraPatterns' => [
  78. 'GET survey' => 'survey',
  79. 'GET captcha' => 'captcha',
  80. 'POST submit' => 'submit',
  81. 'POST enterprise' => 'enterprise',
  82. ],
  83. ],
  84. [
  85. 'class' => 'yii\rest\UrlRule',
  86. 'pluralize' => false,
  87. 'controller' => 'v1/policy',
  88. 'extraPatterns' => [
  89. 'GET policy' => 'policy',
  90. 'GET category' => 'category',
  91. 'GET details' => 'details',
  92. ],
  93. ]
  94. ],
  95. ],
  96. 'request' => [
  97. 'enableCookieValidation' => false,
  98. 'parsers' => [
  99. 'application/json' => 'yii\web\JsonParser',//解析json请求
  100. ]
  101. ],
  102. ],
  103. 'modules' => [
  104. 'v1' => [
  105. 'class' => '\api\modules\v1\Module'
  106. ]
  107. ],
  108. 'params' => $params
  109. ];