我正在 yii2 中编写一个 api 模块并使用子模块进行版本控制。问题是我无法访问子模块中的页面,我只是得到404。这就是我在配置中描述的方式:
'modules' => [
'api' => [
'basePath' => '@app/api',
'class' => app\api\ApiModule::class,
'modules' => [
'v1' => [
'basePath' => '@app/api/v1',
'class' => app\api\v1\V1Module::class,
]
],
'components' => [
'request' => [
'class' => 'yii\web\Request',
'parsers' => [
'application/json' => 'yii\web\JsonParser',
],
'enableCsrfValidation' => false,
'enableCsrfCookie' => false,
],
'response' => [
'class' => 'yii\web\Response',
'formatters' => [
\yii\web\Response::FORMAT_JSON => [
'class' => 'yii\web\JsonResponseFormatter',
'prettyPrint' => YII_DEBUG,
'encodeOptions' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
]
]
]
]
],
],
...
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => ['api/v1/user']],
'/' => 'site/index',
],
],
需要你的帮助。
总的来说,我仍然不明白问题出在哪里,但现在一切正常,设置如下所示: