web/index 的 Yii2 基本模板 UrlManager 规则
Yii2 Basic Template UrlManager rules for web/index
我在 Yii2 基本模板中做了一个 REST API。对于此 REST API,我更改了 web.php。这是我添加的:
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
//basic/web
//basic/web/users
['class' => 'yii\rest\UrlRule', 'controller' => ['user', 'car']],
//basic/web/countries
//Id is een string, vandaar de tokens
['class' => 'yii\rest\UrlRule', 'controller' => 'country', 'tokens' => ['{id}' => '<id:\w+>']],
],
],
这很好用。但现在我无法再从 web 文件夹访问索引页面。我需要添加什么规则才能再次访问 Web 文件夹中的页面?
试试这个,
'rules' => [
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
['class' => 'yii\rest\UrlRule', 'controller' => ['user', 'car']],
//basic/web/countries
//Id is een string, vandaar de tokens
['class' => 'yii\rest\UrlRule', 'controller' => 'country', 'tokens' => ['{id}' => '<id:\w+>']],
]
我在 Yii2 基本模板中做了一个 REST API。对于此 REST API,我更改了 web.php。这是我添加的:
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
//basic/web
//basic/web/users
['class' => 'yii\rest\UrlRule', 'controller' => ['user', 'car']],
//basic/web/countries
//Id is een string, vandaar de tokens
['class' => 'yii\rest\UrlRule', 'controller' => 'country', 'tokens' => ['{id}' => '<id:\w+>']],
],
],
这很好用。但现在我无法再从 web 文件夹访问索引页面。我需要添加什么规则才能再次访问 Web 文件夹中的页面?
试试这个,
'rules' => [
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
['class' => 'yii\rest\UrlRule', 'controller' => ['user', 'car']],
//basic/web/countries
//Id is een string, vandaar de tokens
['class' => 'yii\rest\UrlRule', 'controller' => 'country', 'tokens' => ['{id}' => '<id:\w+>']],
]