dongzou1964 2019-02-22 06:29
浏览 60

Codeigniter:将error_general.php错误重定向到控制器

I have error produced by application/views/errors/html/error_general.php

An Error Was Encountered


Unable to load the requested file: filename.php

But I want to redirect the error to my controller instead like in my error_general.php. Can I do something like?

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
}

Or is there any way to do this?

  • 写回答

1条回答 默认 最新

  • douqian1835 2019-02-22 06:55
    关注

    create file 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
        }
    }
    

    refer codeigniter error handling guide for more help. codeigniter error handling

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程