Answer the question
In order to leave comments, you need to log in
How to formulate REST API requests for YII2?
Good afternoon.
For the first time I work with the YII REST API, and with Api in principle, and I ran into a problem:
According to the official guide, I set up a rest for the users table, return to json, and from the index controller, as it should, a list of all table records is returned to me. However, when I want to reformulate the request to get one record by id, I get 404 in response.
Plus, additional complexity adds that the CNC on the project does not work for me.
Please help me how to write a request for this?
Working query: php.english.local/index.php?r=users
Not working php.english.local/index.php?r=users/1
php.english.local/index.php?r=users%2F1
Answer the question
In order to leave comments, you need to log in
I found the answer, inside yii\rest\ActiveController there
is a list of actions that you need to add after the name of your controller, i.e. for my case
get user with id 1
php.english.local/index.php?r=users/1
should be like this
php.english.local/index.php?r=users/view&id=1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question