0

HTTP GET メソッドで guid 型の主キー値をコントローラーに渡す方法を見つけようとしています。urlManager を次のように変更しました。

'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://localhost/mywebapp/index.php/account/2BE9515F-F388-4974-BCBB-C485C58BDF7A

、結果はまだ HTTP 404 not found です。

しかし、私がのように閲覧すると

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

、正常に動作します。だから問題は何ですか?

4

2 に答える 2

1

ありがとう、マイケル!問題の原因がわかりました!正規表現が正しく一致しません。だから私は次のように変更し、それはうまく動作します:

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

ありがとう!

于 2013-03-31T03:08:39.070 に答える