Reputation: 8540
I'm attempting to create a custom 404 page in CakePHP 2.0 by extending ExceptionRenderer. Everything is working fine except when I output HTML marked-up strings in the View Cake is unwantedly encoding the HTML entities. How can I prevent this from happening?
In my renderer I have:-
class AppExceptionRenderer extends ExceptionRenderer {
public function missingController($error) {
$this->controller->set('test', '<p>Test</p>');
header('HTTP/1.1 404 Not Found');
$this->controller->render('/Errors/error404', 'default');
$this->controller->set('title_for_layout', 'Page Not Found');
$this->controller->response->send();
}
}
In the view (View/Error/error404.ctp):-
<?php echo $test ?>
This outputs <test>
rather than <p>test</p>
.
In my actual code test
will be being set by content from the database as this is a CMS driven site. I'm just setting test
in the renderer code above as an example (and to prove the code is behaving as I am observing).
Upvotes: 0
Views: 1253
Reputation: 1804
You shouldn't be using HTML inside your PHP, you should write any markup in the view file.
I've not come across a situation when you would need to write the markup inside your PHP code, but if you have no other way around it you could always use the html_entity_decode()
function inside your view.
Unfortunately I don't know a way to stop Cake from encoding it automatically like you want.
Upvotes: 3