M
M
may-cat2015-01-16 10:31:35
Yii
may-cat, 2015-01-16 10:31:35

How to set up routes in a Yii2 REST application?

I'm setting up routes in a REST application. it is necessary that the request to /api/basicapp/v01/json/tag/ goes to the tag controller (respectively, to the index action).
How to do it?
Now there is this:

'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'class' => 'yii\rest\UrlRule',
'controller' => 'tag',
]
] ,

but it doesn't provide required part of /api/basicapp/v01/json/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
romankolohanin, 2015-01-16
@may-cat

'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => false,
            'showScriptName' => false,
            'rules' => [

                [   'class'      => 'yii\rest\UrlRule',
                    'controller' => ['tag' => 'tag'],
                    'prefix'     => 'api/basicapp/<version:\w+>/json'
                ]
            ]
      ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question