CI_Exceptions コア クラスを独自の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 (または pre_controller) hookを使用して同様の機能を実現することもできますが、フックが別の目的で既に有効になっている場合にのみ、個人的にはそうします。