B
B
Bags2017-04-19 12:45:20
Yii
Bags, 2017-04-19 12:45:20

How to create action's without ExtraPatterns in Yii2 REST API?

Started writing api for a site in Yii2.
Installed the basic template, created a controller inherited from yii\rest\Controller.
In the URLManager config, I add to the rules each action with the GET or POST type that I create in the controllers. Otherwise, yii gives a 404 error. It's right? If I need to create 50 actions, will I need to add 50 lines 'GET action' => 'action' ???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Guryev, 2017-04-20
@Danakishi

Still there out of the box when it comes to rest api . In the request processing rules, you need to specify the yii\rest\UrlRule class for the desired controller, and there, if necessary, you can expand it using patterns and extraPatterns .
For example, the configuration on one of my projects:

'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => [
                        'v1/product',
                        'v1/user',
                    ],
                ],
             ],
          ],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question