首页 > 解决方案 > Codeigniter:将error_general.php错误重定向到控制器

问题描述

我有错误产生application/views/errors/html/error_general.php

遇到错误


无法加载请求的文件:filename.php

但我想将错误重定向到我的控制器,而不是像我的error_general.php. 我可以做类似的事情吗?

if(substr($message,0,36) == "Unable to load the requested file")
{
    // redirect to my controller
    // $this->My_controller->my_method(); -i don't know what i'm doing here, lol
}

或者有什么办法可以做到这一点?

标签: phpcodeigniter

解决方案


创建文件core/MY_Exceptions.php

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

class MY_Exceptions extends Exception {

    public function __construct($message, $code = 0, Exception $previous = null) {
        parent::__construct($message, $code, $previous);
    }

    public function show_error($heading, $message, $template = 'error_general', $status_code = 500) {
        // do your work here
    }
}

请参阅 codeigniter 错误处理指南以获得更多帮助。 代码点火器错误处理


推荐阅读