在Yii2中,不能将令牌和extrapattern一起用于REST服务

时间:2014-11-27 09:45:29

标签: rest yii2

Yii2 REST query

我发现这是为了在控制器中使用自定义动作,我添加了上面链接中提到的extrapattern

当我们搜索它时工作正常。但是不能使用控制器的正常操作

'urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        'showScriptName' => false,
        'rules' => [
            [
                'class' => 'yii\rest\UrlRule', 
                'controller' => 'v1/country',
                'extraPatterns' => [
                    'GET search' => 'search'
                    ],
                'tokens' => [
                    '{id}' => '<id:\\w+>'
                ]

            ]
        ],        
    ]

此致

1 个答案:

答案 0 :(得分:1)

全部谢谢

经过多次尝试,这解决了我的问题..

          'rules' => [
            [
                'class' => 'yii\rest\UrlRule', 
                'controller' => 'v1/country',
                'extraPatterns' => [
                    'GET search' => 'search'
                    ],                 
            ],
            [
                'class' => 'yii\rest\UrlRule', 
                'controller' => 'v1/country',
                'tokens' => [
                    '{id}' => '<id:\\w+>'
                ]

            ],

        ],