HTTP服务中,当查找不到对应的路由时,会加载/config/route.php
配置文件中的404
配置,判断是否开启自定义错误处理,
当该参数为true
时,则调用error_class
匹配项中,对应的class对象来处理错误逻辑,具体的配置参数示例如下:
<?php
return [
// 找不到路由的时候,是否启用自定义的错误处理程序
'404' => true,
// 自定义的错误处理程序,只需要提供一个类的命名空间位置即可,会把基类Controller的obj注入到第一个参数中,调用fetch即可抛出内容
'error_class' => '\\box\\http_error',
];
namespace box;
use \x\controller\Http;
class http_error extends Http{
/**
* 入口
* @todo 无
* @author 小黄牛
* @version v1.0.1 + 2020.05.29
* @deprecated 暂不启用
* @global 无
* @return void
*/
public function __construct() {
return $this->fetch('HTTP 404', '404');
}
}