Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question