diff --git a/controller/Controller.php b/controller/Controller.php index 9ad7d2c..7628c2b 100644 --- a/controller/Controller.php +++ b/controller/Controller.php @@ -47,7 +47,7 @@ Class Controller { ob_end_flush(); }else { - throw Exception("Layout file not exist: {$layoutFile}", 500); + throw new Exception("Layout file not exist: {$layoutFile}", 500); } } diff --git a/lib/FSC.php b/lib/FSC.php index c278c02..09aaf9d 100644 --- a/lib/FSC.php +++ b/lib/FSC.php @@ -24,7 +24,10 @@ Class FSC { $layoutName = !empty($config['error_layout']) ? $config['error_layout'] : 'error'; $error_layout = __DIR__ . "/../views/layout/{$layoutName}.php"; if (!empty($config['theme'])) { - $error_layout = __DIR__ . "/../themes/{$config['theme']}/views/layout/{$layoutName}.php"; + $theme_error_layout = __DIR__ . "/../themes/{$config['theme']}/views/layout/{$layoutName}.php"; + if (file_exists($theme_error_layout)) { + $error_layout = $theme_error_layout; + } } ob_start(); @@ -63,6 +66,7 @@ Class FSC { return compact('controller', 'action'); } + //add themes support protected static function loadController($config) { //parse url to controller and action $requestUrl = $_SERVER['REQUEST_URI']; @@ -78,16 +82,27 @@ Class FSC { $className = ucfirst($controller) . 'Controller'; $funName = 'action' . ucfirst($action); $controllerFile = __DIR__ . "/../controller/{$className}.php"; + if (!empty($config['theme'])) { + $controllerFile = __DIR__ . "/../themes/{$config['theme']}/controller/{$className}.php"; + } if (file_exists($controllerFile)) { require_once $controllerFile; $cls = new $className(); if (method_exists($className, $funName)) { $cls->$funName(); }else { - throw new Exception("Function {$funName} not exist in class {$className}.", 500); + $error_message = "Function {$funName} not exist in class {$className}."; + if (!empty($config['theme'])) { + $error_message = "Function {$funName} not exist in class {$className} of theme {$config['theme']}."; + } + throw new Exception($error_message, 500); } }else { - throw new Exception("Controller {$className} not exist.", 500); + $error_message = "Controller {$className} not exist."; + if (!empty($config['theme'])) { + $error_message = "Controller {$className} not exist in theme {$config['theme']}."; + } + throw new Exception($error_message, 500); } }