我想顯示404錯誤頁面,因爲我在我的protected/view/system文件夾中創建了error404.php文件。YII如何處理自定義404錯誤頁面以及其他錯誤頁面
默認情況下,我有Sitecontroller,它包含錯誤動作功能如下
public function actionError()
{
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
}
主要配置內部文件,它被定義爲
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
我的問題是,我只需要定製404頁,剩餘的錯誤我需要處理它通過sitecontroller的錯誤函數處理的方式。但我找不到辦法做到這一點。如果假設我刪除「errorAction」 =>「網站/錯誤」,從配置主則它通過調用
throw new CHttpException(404, 'Page not found');
但這樣做,我只能看到頁面而不佈局還包括其他的自定義錯誤顯示404錯誤與404相同,但它們不相同。我多次閱讀手冊,但仍無法解決它。
我不得不改變它到這個'if($ error = Yii :: app() - > errorHandler->錯誤['code'])''error-> code' was給我錯誤。 'getViewFile'也給我這個錯誤。 'CWebApplication及其行爲沒有名爲「getViewFile」的方法或閉包。 (/Applications/XAMPP/xamppfiles/htdocs/wm/common/lib/yii/framework/base/CComponent.php:266)'有什麼想法? – user2636556 2014-03-27 06:28:25
'error-> code'的錯誤信息是'注意:試圖在48行上的/Applications/XAMPP/xamppfiles/htdocs/wm/backend/controllers/SiteController.php中獲取非對象的屬性@Boris – user2636556 2014-03-27 07:06:13
You是對的。應用程序類中沒有getViewFile方法。應該調用控制器的方法:$ this-> getViewFile(...) – 2014-03-31 22:06:00