我正在学习模块如何在Yii2中工作,现在我创建了以下模块:gdpr
。我可以访问以下路线:/index.php?r=gdpr/user/index
。但是,我要访问这样的路由:/gdpr/user/index
。我该如何实现?
config.php:
<?php
return [
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'modules\gdpr\default'],
['class' => 'yii\rest\UrlRule', 'controller' => 'modules\gdpr\user'],
],
],
],
'params' => [
// list of parameters
],
];
答案 0 :(得分:0)
您需要通过以下方式配置控制器:
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => ['gdpr/default', 'gdpr/user'],
],
],
],
],
请参见https://www.yiiframework.com/doc/api/2.0/yii-rest-urlrule#$controller-detail