不能在 Yii2 中为 REST 服务一起使用令牌和 extrapattern [英] Cant use tockens and extrapattern together for REST services in Yii2

查看:37
本文介绍了不能在 Yii2 中为 REST 服务一起使用令牌和 extrapattern的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Yii2 REST 查询

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

I found this for using custom action in the controller for that i added the extrapattern mentioned in the above link

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

And its working fine when we search .but cant use the normal actions for the controller

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

            ]
        ],        
    ]

问候

推荐答案

谢谢大家

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

this solved my problem after lots of trying..

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

            ],

        ], 

这篇关于不能在 Yii2 中为 REST 服务一起使用令牌和 extrapattern的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆