为什么PHP控制器不加载错误文件

时间:2018-12-03 17:09:48

标签: php model-view-controller

我正在使用php开发一个mvc应用

该应用无法加载错误控制器

当我尝试检查是否有错误

停下来,给我空白页

我下面有这个文件

这是.htaccess文件:

php_flag display_errors on
php_value error_reporting 9999

RewriteEngine On
RewriteBase /aiosx/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

我有这个主应用程序文件

private $_url = null;
private $_controller = null;
private $_controllerPath = 'controllers/'; // Always include trailing slash
private $_modelPath = 'models/'; // Always include trailing slash
private $_errorFile = 'error.php';
private $_defaultFile = 'dashboard.php';

public function init(){-
    $this->_getUrl();-
    if (empty($this->_url[0])) {
        $this->_loadDefaultController();
        return false;
    }
    $this->_loadExistingController();
    $this->_callControllerMethod();
}
public function setControllerPath($path) {
    $this->_controllerPath = trim($path, '/') . '/';
}    
public function setModelPath($path) {
    $this->_modelPath = trim($path, '/') . '/';
}
public function setErrorFile($path) {
    $this->_errorFile = trim($path, '/');
}
public function setDefaultFile($path) {
    $this->_defaultFile = trim($path, '/');
}
private function _getUrl() {
    $url = isset($_GET['url']) ? $_GET['url'] : null;
    $url = rtrim($url, '/');
    $url = filter_var($url, FILTER_SANITIZE_URL);
    $this->_url = explode('/', $url);
}
private function _loadDefaultController() {
    require $this->_controllerPath . $this->_defaultFile;
    $this->_controller = new Dashboard();
    $this->_controller->index();
}
private function _loadExistingController() {
    $file = $this->_controllerPath . $this->_url[0] . '.php';
    if (file_exists($file)) {
        require $file;
        $this->_controller = new $this->_url[0];
        $this->_controller->loadModel($this->_url[0], $this->_modelPath);
    } else {
        $this->_error();
        return false;
    }
}
private function _callControllerMethod() {
    $length = count($this->_url);       
    if ($length > 1) {
        if (!method_exists($this->_controller, $this->_url[1])) {
            $this->_error();
        }
    }
    switch ($length) {
        case 5:
            $this->_controller->{$this->_url[1]}($this->_url[2], $this->_url[3], $this->_url[4]);
            break;            
        case 4:
            $this->_controller->{$this->_url[1]}($this->_url[2], $this->_url[3]);
            break;            
        case 3:
            $this->_controller->{$this->_url[1]}($this->_url[2]);
            break;            
        case 2:
            $this->_controller->{$this->_url[1]}();
            break;            
        default:
            $this->_controller->index();
            break;
    }
}    
private function _error() {
    require $this->_controllerPath . $this->_errorFile;
    $this->_controller = new Error();
    $this->_controller->index();
    exit;
}

为什么此应用程序未加载erorr控制器 我一直在检查每件事,请帮助我

0 个答案:

没有答案