简体   繁体   中英

create extrapattern in yii2

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

host : http://localhost/eg_integration/api/web/v1 controller : devices contant term : registrations, passesUpdatedSince

Url rule code:

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

hot to handle this url in extrapattern

Given that the url is constant, I would set a rule like this:

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

Then in your deviceController you get the query parameter:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM