Extend the CI_Exceptions core class用自己的show_error
功能。使用原代碼爲show_error
,但沿着這些線路增加一個快速檢查,以開頭:
class MY_Exceptions extends CI_Exceptions {
/**
* General Error Page
*
* This function takes an error message as input
* (either as a string or an array) and displays
* it using the specified template.
*
* @access private
* @param string the heading
* @param string the message
* @param string the template name
* @return string
*/
function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
// First try forwarding to all-lowercase URL if there were caps in the request
if ($_SERVER['REQUEST_URI'] != strtolower($_SERVER['REQUEST_URI']))
{
header('Location: ' . strtolower($_SERVER['REQUEST_URI']));
return;
}
/* Rest of original function to follow... */
自視需要牢記,你可能希望有大寫的URI的其他部分。
你也可以用pre_system (or pre_controller) hook實現類似的功能,但我個人只會這樣做,如果掛鉤已經用於其他目的。
乾杯..我沒有把這個在我的灌輸索引頁: $ _SERVER ['REQUEST_URI'] = strtolower($ _ SERVER ['REQUEST_URI']); 沒有變化..所有上述例子仍然是404頁,而不是重寫。我是猴子嗎?這不是正確的方法嗎? – Beertastic
它是爲你工作? – pinaldesai
嘗試路由http://codeigniter.com/user_guide/general/routing.html – pinaldesai