尝试将路由中的控制器名称小写:
$route['404_override'] = 'my404';
如果这不能解决你的问题,请报告。
关于在没有匹配路由的情况下需要自定义生成的404时该怎么办,我创建了一个文件/应用程序/核心/我的U异常。php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Exceptions extends CI_Exceptions {
/**
* Class constructor
*/
public function __construct()
{
parent::__construct();
}
// --------------------------------------------------------------------
/**
* 404 Error Handler
* -----------------
* This method has been extended so that if we use the show_404
* function, that it is a styled/custom 404 page that is shown.
*/
public function show_404( $page = '', $log_error = TRUE )
{
if( is_cli() )
{
$heading = 'Not Found';
$message = 'The controller/method pair you requested was not found.';
}
else
{
$heading = '404 Error - Page Not Found';
$message = 'The page or resource you were looking for was not found on this server.';
}
// By default we log this, but allow a dev to skip it
if( $log_error )
{
log_message('error', $heading . ': ' . $page );
}
if( is_cli() )
{
echo $this->show_error($heading, $message, 'error_404', 404);
}
else
{
$CI = &get_instance();
$CI->output->set_status_header('404');
$view_data = [
'heading' => $heading,
'message' => $message
];
$data = [
'doc_title' => ['pre' => '404 Error - Page Not Found - '],
'extra_head' => '<meta name="robots" content="noindex,nofollow" />',
'content' => $CI->load->view( 'errors/html/error_404', $view_data, TRUE )
];
$CI->load->view('templates/main', $data);
echo $CI->output->get_output();
}
exit(4); // EXIT_UNKNOWN_FILE
}
// --------------------------------------------------------------------
}
注意,按照我的方式,我将error\u 404视图嵌套在我创建的模板中。我就是这样做的。当你在应用程序(通常是你的控制器)中创建页面时,你会用你使用的东西来替换这个部分。