too long

My Folder and code strucure is -

api/
    modules/
        v1/
            controllers/
                UserController.php
                BaseController.php
            Module.php
        v2/
            controllers/
                UserController.php
                BaseController.php
            Module.php

And my application configuration would look like:

'modules' => [
        'v1' => [
            'basePath' => '@app/modules/v1',
            'class' => 'api\modules\v1\Module'
        ],
         'v2' => [
            'basePath' => '@app/modules/v2',
            'class' => 'api\modules\v2\Module'
        ],
     ],
'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => false,
            'showScriptName' => false,
            'rules' => [

                    ['class' => 'yiiest\UrlRule', 'controller' => ['v2/user']],
                    ['class' => 'yiiest\UrlRule', 'controller' => ['v1/user']],
],
]

I am following the same procedue as given on yii2 doc But its versioning not working .

UPDATE : I have created a costume rule and parse according that . Looking for something else .

    class ApiUrlRule implements UrlRuleInterface {

    public function parseRequest($manager, $request) {
        $pathInfo = $request->getPathInfo();
        $paramas=$request->getQueryParams();


        $version=Yii::$app->response->acceptParams['version'];
        $route = Yii::$app->response->acceptParams['version'].'/'.$pathInfo;
         return [$route,$paramas];
    }

public function createUrl($manager, $route, $params) {

}


}

From the docs you linked:

Both methods have their pros and cons, and there are a lot of debates about each approach. Below you'll see a practical strategy for API versioning that is a mix of these two methods:

  • Put each major version of API implementation in a separate module whose ID is the major version number (e.g. v1, v2). Naturally, the API URLs will contain major version numbers.

  • Within each major version (and thus within the corresponding module), use the Accept HTTP request header to determine the minor version number and write conditional code to respond to the minor versions accordingly.

The major api version number is determined by the url, as you've set in your urlManager. You can access them by calling your-yii2-app.com/v1/controller/action or your-yii2-app.com/v2/controller/action. Any code that parses the header must be written by you:

Accept HTTP request header to determine the minor version number and write conditional code to respond to the minor versions accordingly.

If you want to write a custom api version header functionallity, this is possible. I suggest you try and create a new question if you run into trouble.