gpt4 book ai didi

codeigniter - show_404() 中的自定义 View 不起作用

转载 作者:行者123 更新时间:2023-12-04 02:44:27 25 4
gpt4 key购买 nike

我已经尝试了 404_override 和 MY_Exceptions 来显示自定义错误 View 。有人可以帮我吗?

这是 404_override 代码

路由.php

$route['404_override'] = 'error/index';

错误.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Error extends CI_Controller {

public $user_id ='';

function __construct()
{
parent::__construct();
$this->load->library('login.php');
$user_Details = $this->login_library->get_user_details();
$this->user_id = $user_Details['user_id'];
}

public function index()
{
$this->output->set_status_header('404');
$this->output->set_status_header('404');
$this->load->view('view_header',$this->user_id);
$this->load->view('view_404');
$this->load->view('view_footer',$this->user_id);
}



}

这是 My_Exceptions 代码
<?php  if (! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Exceptions extends CI_Exceptions{

function MY_Exceptions(){
parent::CI_Exceptions();
$this->CI =& get_instance();
}

function show_404($page=''){
echo $heading = "404 Page Not Found";
echo $message = "The ppage you requested was not found.";
$this->config =& get_config();
$baseUrl = $this->config['base_url'];
header("location: ".$baseUrl.'error.html');
exit;
}

}

最佳答案

我从这个链接得到了解决方案 - CodeIgniter 2.1 issue with show_404() and 404_override .

<?php
// application/core/MY_Exceptions.php
class MY_Exceptions extends CI_Exceptions {

public function show_404()
{
$CI =& get_instance();
$CI->load->view('my_notfound_view');
echo $CI->output->get_output();
exit;
}
}

非常感谢所有的帮助。赞赏:)

关于codeigniter - show_404() 中的自定义 View 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22511725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com