2016-05-30 45 views
0

我是CodeIgniter的新手,我的路由配置有一些問題。CodeIgniter顯示頁面沒有css而不是404

一切工作正常,如果我訪問一個頁面,因爲它應該是

http://localhost/index.php/class/controller

但是,如果我加入一些隨機參數

http://localhost/index.php/class/controller/randomStuff

它顯示的頁面沒有CSS或JS,但我想顯示一個404錯誤頁面。

這是我route.php文件在您的幫助

$route['stats'] = 'main/account'; 
$route['/'] = 'index.php'; 
$route['/(:any)'] = 'main/disperr'; //Tried this to solve the problem but doesn't work (disperr simply returns show_404()) 
$route['default_controller'] = 'main'; 
$route['all'] = 'main'; 
$route['404_override'] = 'errors/page_missing'; 
$route['translate_uri_dashes'] = FALSE; 

感謝。

編輯:謝謝你的回答! 正確路由頁面後,我stil有缺少的CSS問題。 當我使用樹枝時,我將base_url()作爲參數發送給我的視圖,並將其添加到我的CSS和JS的路徑中。 現在有效。

回答

0

您可以普萊舍以下網址

http://localhost/class/index.php/main

你需要給你的控制器的名稱的index.php後(沒有文件夾名稱控制器)

+0

謝謝,我編輯了這個問題。 –

0

你必須遵循來自文檔頁面的一些規則。 您在CodeIgniter安裝後找到的路線必須位於開頭,以便找到這些路線。

$route['default_controller'] = 'main';//Main class need to have index() method for this works 
$route['404_override'] = 'errors/page_missing'; 
$route['translate_uri_dashes'] = FALSE; 

您必須注意優先順序,因爲規則將被讀取以便在文件中定義這些規則。

$route['all'] = 'main'; 
$route['stats'] = 'main/account'; 
$route['(:any)'] = 'main/disperr'; //Tried this to solve the problem but doesn't work (disperr simply returns show_404()) 

如果你有(:any)通配符佔位符,它是在文件的結尾,因爲你必須檢查所有的具體路線不通過(:任何)規則,因爲該規則適用於任何途徑(如姓名建議)。因爲斜槓是默認控制器並且已被定義,所以不需要對路由索引進行索引。路由到index.php是無效的,你應該路由到'controller_name/method_name/param1'或類似的模式。開始時不需要斜線,因爲你看到我刪除了這些。也許從製作的路線開始刪除斜槓將解決您的CSS問題,但您需要遵循我在此處公開的其他文檔規則。閱讀全文here