0

I'm trying to figure out how to pass the guid type primary key value in the HTTP GET method to the controller. I have changed my urlManager as follows:

'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>',
        ),
    ),

When I browse like

http://localhost/mywebapp/index.php/account/2BE9515F-F388-4974-BCBB-C485C58BDF7A

, the result is still HTTP 404 not found.

But when I browse like

http://localhost/mywebapp/index.php/account/index

, it works fine. So what's the problem?

4

2 回答 2

1

The first matching rule wins. In your case, it's likely that the URL rule '<controller:\w+>/<id:\d+>' matches /account/2BE9515F-F388-4974-BCBB-C485C58BDF7A (<controller>=account and <id>=2). You should move your second rule to the top.

Rule of thumb: More specific URL rules should be listed before more general rules.

于 2013-03-30T17:12:41.270 回答
1

Thanks agian, Michael! I have found what the problem lays on! The regular expression can not match properly. So I changed as follows and it works fine:

'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>',
        ),
    ),

Thanks!

于 2013-03-31T03:08:39.070 回答