<?php
class My404 extends CI_Controller{
public function __construct() {
parent::__construct();
}
public function index() {
$this->output->set_status_header('404');
$this->load->view('err404');
}
}
$route['404_override'] = 'my404';
<?php defined('BASEPATH') OR exit('No direct script access allowed');
$ci = new CI_Controller();
$ci =& get_instance();
$ci->load->helper('url');
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="utf-8">
<title>Hata Sayfası</title>
</head>
<body>
<div>
<p>Özel Codeigniter 404 Hata Sayfaları Nasıl Oluşturulur</p>
<div>
<p><a href="<?php echo base_url(); ?>">Evine geri dön</a></p>
</div>
</div>
</body>
</html>
class Error extends Controller {
function error_404() {
$this->output->set_status_header('404');
echo "404 - not found";
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Router extends CI_Router {
var $error_controller = 'error';
var $error_method_404 = 'error_404';
function My_Router(){
parent::CI_Router();
}
function _validate_request($segments) {
if (file_exists(APPPATH.'controllers/'.$segments[0].EXT)){
return $segments;
}
if (is_dir(APPPATH.'controllers/'.$segments[0])){
$this->set_directory($segments[0]);
$segments = array_slice($segments, 1);
if (count($segments) > 0){
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT)){
return $this->error_404();
}
}else{
$this->set_class($this->default_controller);
$this->set_method('index');
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT)){
$this->directory = '';
return array();
}
}
return $segments;
}
return $this->error_404();
}
function error_404(){
$this->directory = "";
$segments = array();
$segments[] = $this->error_controller;
$segments[] = $this->error_method_404;
return $segments;
}
function fetch_class(){
$this->check_method();
return $this->class;
}
function check_method(){
$ignore_remap = true;
$class = $this->class;
if (class_exists($class)){
$class_methods = array_map('strtolower', get_class_methods($class));
if($ignore_remap && in_array('_remap', $class_methods)){
return;
}
if (! in_array(strtolower($this->method), $class_methods)){
$this->directory = "";
$this->class = $this->error_controller;
$this->method = $this->error_method_404;
include(APPPATH.'controllers/'.$this->fetch_directory().$this->error_controller.EXT);
}
}
}
function show_404(){
include(APPPATH.'controllers/'.$this->fetch_directory().$this->error_controller.EXT);
call_user_func(array($this->error_controller, $this->error_method_404));
}
}
$this->router->show_404();