Hello! I cant figure out how to specify a different layout for the CHttpException.
On my site im using several layouts, e.g. one for popups that i call generalPopup.php and other for normal site views, called main.php. I want that if an http error in a popup is shown, the error.php should use the layout generalPopup.php
Now the error is rendered with the main.php, that also contains header and footer. . How can i accomplish this? Using $this->layout = ‘generalPopup’ before the throw new CHttpException(404,‘Popup was not found’); doesnt work.
I implemented a quick and dirty function in SiteController, wich looks if the error message has popup string at the begining. But i dont want to use this solution on my production site. Has anyone a better idea?
public function actionError()
{
if($error=Yii::app()->errorHandler->error) {
error_log(substr($error['message'], 0, 5));
if(strcasecmp(substr($error['message'], 0, 5),'popup') == 0) {
$error['message'] = substr($error['message'], 5);
$this->layout = 'generalPopup';
}
$this->render('error', array(
'error' => $error
));
}
}