0
我試圖通過擴展ExceptionRenderer在CakePHP 2.0中創建一個自定義404頁面。除非在View Cake中輸出HTML標記的字符串時不需要編碼HTML實體,否則一切正常。我怎樣才能防止這種情況發生?CakePHP通過ExceptionRenderer在View輸出中不必要地編碼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 /錯誤/ error404.ctp): -
<?php echo $test ?>
此輸出<test>
而非<p>test</p>
。
在我的實際代碼test
將由數據庫中的內容設置,因爲這是一個CMS驅動的網站。我只是在上面的渲染器代碼中設置test
作爲示例(並且證明代碼的行爲與我觀察的一樣)。
我完全同意HTML不屬於PHP。我正在開發一個CMS驅動的站點,需要從數據庫中檢索這些內容。我只是把上面的代碼中的$ test變量作爲一個例子,並測試它沒有被數據庫作爲編碼返回。 'html_entity_decode()'確實有用,但是想知道Cake爲什麼要這麼做。當我在我的控制器中設置變量時,在我的應用程序的其他地方不會出現此問題。 – drmonkeyninja