【发布时间】:2012-12-11 12:39:35
【问题描述】:
我正在尝试通过扩展 ExceptionRenderer 在 CakePHP 2.0 中创建自定义 404 页面。一切工作正常,除非我在 View Cake 中输出 HTML 标记字符串时对 HTML 实体进行了不必要的编码。我怎样才能防止这种情况发生?
在我的渲染器中我有:-
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();
}
}
在视图中(View/Error/error404.ctp):-
<?php echo $test ?>
这会输出&lt;test&gt; 而不是<p>test</p>。
在我的实际代码中,test 将由数据库中的内容设置,因为这是一个 CMS 驱动的站点。我只是在上面的渲染器代码中设置test 作为示例(并证明代码的行为符合我的观察)。
【问题讨论】:
标签: cakephp cakephp-2.0