2012-02-13 26 views
2

我在定製CI error_404.php文件位於application/errors/error_404.php的過程是,但不知何故不承認輔助功能base_url()。是因爲這是一個錯誤而不是一個觀點?笨:傳遞輔助函數的CI error_404.php文件

url已經在config.php中自動加載時,我該如何傳遞幫助函數?

編輯:我顯然只是試圖自定義我的404頁面。我看着這個錯誤的方式嗎?

+0

見http://codeigniter.com/forums/viewthread/172619/#820845 – 2012-02-13 12:31:21

+1

如果您正在運行CI2你可以只設置404_override路線的錯誤控制器。這不會影響show_404()404頁面,儘管http://codeigniter.com/user_guide/general/routing.html – 2012-02-13 13:14:11

回答

0

問題是在自動加載項目被調用之前很久就會顯示404錯誤。

這裏是我會做:

<?php 
if(!function_exists('base_url')) 
{ 
    include BASEPATH.'helpers/url_helper.php'; 
} 
?> 

// 404 error content here... 
0

您可以使用

$this->config->config['base_url']; 

如果你想要做一個constants.php

print_r($this); 
+0

我也嘗試過'print_r($ this)',但是在errors/error_404.php頁面上的結果只是一個例外: CI_Exceptions對象 ( [動作] => [嚴重性] => [消息] => [文件名] => [行] => [ob_level] => 0 [水平] =>數組 ( [1] =>錯誤 ... [2048] =>運行時通知 ) ) – 2014-03-12 18:05:48

0

只要定義BASE_URL爲常數和要求那個constants.php在error404.php

4

這裏是我會做什麼: error_404.php

$CI =& get_instance(); 
if(! isset($CI)) 
{ 
    $CI = new CI_Controller(); 
}