【问题标题】:create extrapattern in yii2在yii2中创建extrapattern
【发布时间】:2016-04-23 14:07:09
【问题描述】:

网址:http://localhost/eg_integration/api/web/v1/devices/cacf090690d9dab14df06219ac36b3cd/registrations/pass.usa.gift?passesUpdatedSince=1232

主机:http://localhost/eg_integration/api/web/v1 控制器:设备 持续术语:注册,passUpdatedSince

网址规则代码:

'class' => 'yii\rest\UrlRule',
                                    'controller' => 'v1/devices',
                                    'pluralize' => false,
                                    'extraPatterns' => [ 
   'GET registration' => 'getserialnumber', 
]

在extrapattern中处理这个url很热

【问题讨论】:

    标签: php yii2 yii2-advanced-app url-mapping


    【解决方案1】:

    鉴于 url 是不变的,我会设置这样的规则:

    'GET cacf090690d9dab14df06219ac36b3cd/registrations/pass.usa.gift' => 'getserialnumber',
    

    然后在你的 deviceController 中你得到查询参数:

    public function actionGetserialnumber() {
        ...
        $value = Yii::$app->getRequest()->getQueryParam('passesUpdatedSince', $defaultValue)
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-29
      相关资源
      最近更新 更多