E
E
evilelf2019-08-16 15:40:54
Yii
evilelf, 2019-08-16 15:40:54

How to make routing for Yii2 with version passing in Accept?

Hello.
I am making a restful api on yii2.
How to make it so that the router goes to the v1 or v2 module when passing the required version in the Accept header?
There is a dock here: https://www.yiiframework.com/doc/guide/2.0/en/rest...
It works with passing the version to the url, but not with Accept.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
evilelf, 2019-08-16
@evilelf

so far I've implemented it like this:

'rules' => [
      [
        'class' => \yii\web\GroupUrlRule::class,
        'rules' => [
          '<_c>/<_a>' => '<_c>/<_a>',
        ],
        'prefix' => 'api',
        'routePrefix' => 'v1',
      ],
      .....
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question