Yii2基本模板用于web /索引的UrlManager规则

时间:2016-02-04 10:49:35

标签: php yii2 yii2-basic-app yii-url-manager

我在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文件夹访问页面?

1 个答案:

答案 0 :(得分:1)

试试这个,

'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+>']],
]