I want to add more variables to the query string of error page when I throw new CHttpException, ex
http://localhost/site/error?variable1=xyz&variable2=abc
I have searched around, but there isn’t solution for this issue.
I want to add more variables to the query string of error page when I throw new CHttpException, ex
http://localhost/site/error?variable1=xyz&variable2=abc
I have searched around, but there isn’t solution for this issue.
Well, have you tried to add arguments to SiteController’s actionError() method?
public function actionError($variable1 = null, $variable2 = null) {
// ...
}
but how to pass argument from throw new exception to actionError?
Well, some ideas for you:
[list=1][*]Create your own exception class that extends CHttpException for example.
Declare a property for this new class, for example $variables:
class MyHttpException extends CHttpException {
public $variables = array();
}
Now way you can either override the constructor, by redefining $message parameter to be used as array:
public function __construct($status,$message=null,$code=0)
{
$this->statusCode=$status;
if (null !== $message && is_array($message)) {
$this->variables = $message;
parent::__construct($this->variables['message'],$code);
} else {
parent::__construct($message,$code);
}
}
or add a fifth construct parameter $variables:
public function __construct($status,$message=null,$code=0,$variables=null)
{
$this->statusCode=$status;
if (null !== $variables && is_array($variables)) {
$this->variables = $variables;
}
parent::__construct($message,$code);
}
[*]You can also use session to store the variables.[/list]
Keep mind that I haven’t tested the above code.