Hello! I am trying to define rules for REST API. I have three rules for actions like CREATE, VIEW and DELETE, so I decided to use HTTP verb to identify them. Here is urlManager array:
I don’t see an error at first sight (despite the “patern” typo in your first rule) but maybe you still have a default route in your config some were? I am asking because the rules Yii creates by default would route “controller/id” to “controller/view”.
I believe the view action applies for both your intended delete and your actual view actions because their patterns are the same. Fortunately you didn’t invert their entries: the delete action would then apply in both cases.
Simple solution: change the delete entry’s pattern.
Don’t know if I can remove it, because web app has non-REST part, written by other people.
The problem is that I can not call Controller::actionDelete() with DELETE request (it calls Controller::actionView(), that should be called with GET verb).
Then try to move this rule at the end of your rules. The urlManager goes down the list and as soon as it finds a matching rule it is applied. So if the mentioned one comes first and you didn’t define a verb (which you didn’t in this case) it would also match DELETE requests.
By the way. I don’t see any reason for this additional rule. It is actually doing the same as your one with the GET rule doesn’t it? Meaning it leads to the same controller/action
I thought about that one too but if you rethink it it would be a horrible bug. Because most people would never think about the possibility of routing a GET to a DELETE action just because the order of the entries is wrong. If that would be the case it would be really bad, hope it is not the case
Thank you, I think I got it after your explanation. I did something like "override" in config (used main app config, merged with my specific one). So I think, I should define my config without it, because REST and non-REST parts of app use different entries.