I'm handling 404s with the line CHttpException(404, $message), and the $message variable is an HTML string to achieve some styling. But CHttpException() encodes my $message, rendering the HTML as a useless escaped string. Is there any way around the string encoding of CHttpException, in order to output HTML?
/**
* From PostsController.php
*/
// ...
public function actionCategory($id)
{
$categoryModel = Categories::model()->findByAttributes(array('idCategory'=>$id));
if($categoryModel===null){
$message = "<div class=\"alert alert-danger\">Page Not Found</div>";
throw new CHttpException(404, $message);
return;
}
// ...
CHttpException
does not encode anything. By default message is encoded in error view which is in protected/views/site/error.php
- I suppose you only have to change it in that view (or your custom error view if you did change that). Only you should be aware that standard errors thrown by yii are not prepared for HTML so you should find some way to distinguish between CHttpException thrown by your code and that thrown by Yii.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With