我扩展了codeigniter本机库(例外)并定义了一个新函数。
这是代码
class MY_Exceptions extends CI_Exceptions {
public function __construct() {
parent::__construct();
}
public function show_error($heading, $message, $template = 'error_general', $status_code = 500) {
try {
} catch (Exception $e) {
}
}
public function custom_errors($id, $message) {
try {
//some code here
} catch (Exception $e) {
}
}
}
我将这个上面的类放在application/core/My_Exceptions.php
中用于自动加载,如文档中提到的那样。 https://www.codeigniter.com/user_guide/general/core_classes.html
问题是,当custom_errors($id, $message)
在同一控制器中可用时,我无法访问控制器中的函数show_error()
我试试这个
$this->my_exceptions->custom_errors($id, $message)
并且
$this->exceptions->custom_errors($id, $message)
但是得到这个错误“在非对象上调用成员函数custom_errors()”
如果codeigniter自动加载它,那么它应该在这里可用。
请帮助我,我做错了什么?