moylua
(Moylua)
1
Hi, i have a REST API that uses uuid as the id of a model. For example, "example.com/items/cvxcv-2312-xcvx-sdfsdf"
unfortunately yii2 treats this as error 404. but if i replace the id with "example.com/items/123" there is a response
i tried to change in the web.php file url manager but i’m still figuring it out. I need help. Thanks
It is right because item detail accept a number (\d+) as parameter.
Check the urlManager in config/main.
softark
(Softark)
3
The rules for the url manager must treat UUID as a string, because it has ‘-’ and ‘a’ to ‘f’.
Does your model have a corresponding UUID other than id?
If yes, you could retrieve the id from the UUID.
moylua
(Moylua)
4
can’t find the syntax in urlmanager to have this pattern. the docs is not clear. can’t also find in stackoverflow
moylua
(Moylua)
5
my url manager
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => ['item'],
'pluralize' => true,
],
]
],
moylua
(Moylua)
6
found on the forums tried this works on uuid but better if the length of each uuid string is specified
[
'class' => 'yii\rest\UrlRule',
'controller' => ['item'],
'pluralize' => true,
'tokens' => [
'{id}' => '<id:\\w+-\\w+-\\w+-\\w+-\\w+>'
]
],