如何处理Yii'中的guid或uuid类型主键;s urlManager而不是仅数字类型?
我试图弄清楚如何将HTTP GET方法中的guid类型主键值传递给控制器。 我已将我的urlManager更改如下:如何处理Yii'中的guid或uuid类型主键;s urlManager而不是仅数字类型?,yii,primary-key,guid,uuid,Yii,Primary Key,Guid,Uuid,我试图弄清楚如何将HTTP GET方法中的guid类型主键值传递给控制器。 我已将我的urlManager更改如下: 'urlManager'=>array( 'urlFormat'=>'path', 'rules'=>array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controll
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<id:^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$>'=>'<controller>/view',
'<controller:\w+>/<action:[a-zA-Z_]+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:[a-zA-Z_]+>/<id:^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$>'=>'<controller>/<action>',
'<controller:\w+>/<action:[a-zA-Z_]+>'=>'<controller>/<action>',
),
),
,结果仍然是HTTP 404未找到
但是当我浏览时喜欢
http://localhost/mywebapp/index.php/account/2BE9515F-F388-4974-BCBB-C485C58BDF7A
http://localhost/mywebapp/index.php/account/index
,它工作得很好。
那么问题出在哪里呢?第一条匹配规则获胜。在您的情况下,URL规则很可能与
'/'
匹配/account/2BE9515F-F388-4974-BCBB-C485C58BDF7A
(
=账户和
=2
)。你应该把第二条规则移到最上面
经验法则:更具体的URL规则应该在更一般的规则之前列出。再次感谢Michael!
我发现了问题的症结所在!正则表达式无法正确匹配。
所以我做了如下修改,效果很好:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:[({]?(0x)?[0-9a-fA-F]{8}([-,]?(0x)?[0-9a-fA-F]{4}){2}((-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12})|(,\{0x[0-9a-fA-F]{2}(,0x[0-9a-fA-F]{2}){7}\}))[)}]?>'=>'<controller>/view',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:[a-zA-Z_]+>/<id:[({]?(0x)?[0-9a-fA-F]{8}([-,]?(0x)?[0-9a-fA-F]{4}){2}((-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12})|(,\{0x[0-9a-fA-F]{2}(,0x[0-9a-fA-F]{2}){7}\}))[)}]?>'=>'<controller>/<action>',
'<controller:\w+>/<action:[a-zA-Z_]+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:[a-zA-Z_]+>'=>'<controller>/<action>',
),
),
'urlManager'=>数组(
“urlFormat'=>“路径”,
'规则'=>数组(
“/”=>“/视图”,
“/”=>“/视图”,
'//'=>'/',
'//'=>'/',
'/'=>'/',
),
),
谢谢 谢谢你,迈克尔!我按照你说的做了改变:“/”=>“/视图“/”=>“/视图“/”、“/”=>“/”、“/”=>“/”、“/”=>“/”,但它不起作用!我怎样才能修好它?