yii2: yii\rest\UrlRule doesn't support route params.
What steps will reproduce the problem?
on config/main.php
'urlManager' => [
'rules' => [
[
'class' => \yii\rest\UrlRule::class,
'controller' => ['store/<store_id:\d+>/employee' => 'store-employee'],
],
],
],
What is the expected result?
use the StoreEmployeeController
controller when accessing the route store/1/employee
What do you get instead?
http status 404 the rest rule is not even parsed.
Additional info
caused by line https://github.com/yiisoft/yii2/blob/master/framework/rest/UrlRule.php#L221 since it executes
strpos('store/1/employee', 'store/<store_id:\d+>/employee')
which obviously will return false. there is no work-around this. when removing this line (and the ending bracket) the url is parsed properly.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (18 by maintainers)
@Faryshta first of all, tests which are missing for validating current behavior. These should go in a separate pull request which doesn’t change framework code. Then changes + tests for new behavior.
Overall I see why it could be handy. I still find it a bit confusing about using patterns in
controller
but since there’s key=>value syntax anyway I think it’s acceptable.I do not think this is a good idea to support this inside $controller property. Using $prefix looks like a better solution to me.