Url manager and error handling.

Hi.

I have a problem with yii error handling and url manager.

Users from a desktop app are redirected to yii site with their client id as a get parameter, the client id has 32 character/numbers and i’m using this rule in url manager:

‘rules’ => array(

              'pay/<key:[a-zA-Z0-9]+>' => 'pay/go',


        ),

The problem is that if someone inputs a client id with some special chars like “-”, “=” etc. he gets and error message “The system is unable to find the requested action”, but i don’t want to show this error message and instead of that just show “your client id is wrong”.

How can i do that and override the default error system? Maybe i should not use the regex in url rules but pass anything and validate in action, what you think ?

I run into this frequently, and prefer to validate the client ID in the controller, e.g.




public function actionGo($key) {

   $this->validateKey($key);

   // ...

}

public function validateKey($key) {

   // Figure out if key is valid, and set $valid to that value

   if ($valid)  return;

   // Invalid. Handle however you like, e.g., throwing an exception

   throw new CHttpException(400, 'Invalid request.');

}



If ‘key’ is simply missing in the query string, the user gets the error always given when an action has a required parameter and it’s missing. If ‘key’ is present in the query string, but invalid, you can handle it yourself, as shown.

:mellow:

Yeah i think this is the better way thx.