-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yii\rest\UrlRule doesn't support route params. #13968
Comments
Your config looks really weird, why are you configuring the class of UrlManager to be yii\rest\UrlRule? |
@cebe my bad i fixed the original example |
From the PHPdoc:
what makes you think it could contain parameters? |
if it doesn't support route params then lets add support to route params. http://www.yiiframework.com/doc-2.0/yii-rest-urlrule.html#$controller-detail
it make sense to be able to have a pattern like the one i mention on my example. |
@cebe so can i make a pr with the support for this? |
I do not think this is a good idea to support this inside $controller property. Using $prefix looks like a better solution to me. |
@cebe thats suboptimal specially when handling all the controllers in an api 'rules' => [
[
'prefix' => 'api/v1/',
'class' => \yii\rest\UrlRule::class,
'controller' => [
'store',
'store/<store_id:\d+>/employee' => 'store-employee'
],
],
], make more sense than your alternative. adding the support can be done with removing just one line of code and as @tunecino pointed this feature has been requested since 2015. |
@samdark @SilverFire any input on this? |
Controller ID should not contain anything but controller ID. |
So that leaves us with either extra patterns and prefixes. |
@samdark the docs mentions that the key can support patterns and the value is the controller id it points to |
Nope:
|
It could be done using prefixes and 2 different rules: 'rules' => [
[
'prefix' => 'api/v1/',
'class' => \yii\rest\UrlRule::class,
'controller' => ['store'],
],
[
'prefix' => 'api/v1/store/<store_id:\d+>/',
'class' => \yii\rest\UrlRule::class,
'controller' => [
'employee' => 'store-employee'
],
]
], This is also related to https://github.com/yiisoft/yii2/issues/7878 as we can also introduce a new advanced UrlRule class for it. My attempt for it was this one which was based on this idea: https://github.com/yiisoft/yii2/issues/7878#issuecomment-86485350 |
I don't see how that is easier to maintain, understand or add new resources than
Specially when dealing with several resources in the same api. The fix will be just deleting one line of code and it would be 100% backward compatible and would fix several issues such as #8153 and #9474 |
well. I agree with you in that. I think if |
@tunecino https://github.com/tecnocen-com/yii2-roa/blob/master/src/UrlRule.php i only removed an @samdark which tests should i write on the pr? |
@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 |
Issue moved to yiisoft/yii-api#7 |
What steps will reproduce the problem?
on config/main.php
What is the expected result?
use the
StoreEmployeeController
controller when accessing the route store/1/employeeWhat 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.
The text was updated successfully, but these errors were encountered: