這是我有:定製cakeError
comments_controller.php
if (empty($result)) { //$result is empty if comment does not exist
$this->cakeError('error404', array('message'=>'Comment not found'));
} elseif ($result['spam'] == 1) {
$this->cakeError('spam', array('message'=>'SPAM!!!'));
}
app_error.php
function error404($params) {
$this->controller->set('title', 'Page not found');
$this->controller->set('message', $params['message']);
$this->_outputMessage('error404');
}
function spam($params) {
$this->controller->set('title', 'Spam');
$this->controller->set('message', $params['message']);
$this->_outputMessage('spam');
}
我創建error404.ctp和垃圾郵件.ctp裏面應用程序/視圖/錯誤
的問題是,當評論是垃圾郵件($結果[ '垃圾郵件'] == 1),CakePHP的加載error404佈局。但奇怪的是,它顯示了垃圾評論的消息(「垃圾郵件!!!」)。
當它是不存在的評論,正確的error404佈局被加載。
任何想法?
編輯:問題固定。代碼是正確的,但服務器必須重新啓動。這不應該是必要的,但這是解決問題的辦法。也許蛋糕沒有遵循新的* app_error.php *文件的正確路徑。
了哪些應用程序/配置/ core.php中調試的價值? – dhofstet 2011-04-07 07:26:48
Configure :: write('debug',0); 現在是固定的。 – rlcabral 2011-04-07 09:58:31
蛋糕錯誤聽起來很有趣。 – 2011-04-07 10:09:12