diff --git a/src/base/BaseController.php b/src/base/BaseController.php index 44cd8a5bc802171e8012cef506648b2d698337c7..5de245a9a40595ef70b43f18ac0a809ef9fa2c3a 100644 --- a/src/base/BaseController.php +++ b/src/base/BaseController.php @@ -43,7 +43,19 @@ abstract class BaseController public function handle($method, $urlParams) { - $lowMethod = strtolower($method); - echo $this->$lowMethod($urlParams); + $to_lower_method = strtolower($method); + echo $this->$to_lower_method($urlParams); + } + + protected static function render($data, $view, $layout) + { + extract($data); + ob_start(); + include_once __DIR__ . "/../../views/{$view}.php"; + $content = ob_get_clean(); + + $data["__content"] = $content; + extract($data); + include_once __DIR__ . "/../../views/{$layout}.php"; } } diff --git a/src/controllers/MainController.php b/src/controllers/MainController.php new file mode 100644 index 0000000000000000000000000000000000000000..5afc1913ea99b5ddc36089f4633da23471f50e76 --- /dev/null +++ b/src/controllers/MainController.php @@ -0,0 +1,53 @@ +<?php + +namespace app\controllers; + +use app\base\BaseController; +use app\exceptions\MethodNotAllowedException; +use Exception; + +class MainController extends BaseController +{ + + protected function __construct() + { + parent::__construct(null); + } + + protected function get($urlParams) + { + try { + // parent::get($urlParams); + + // echo "params is "; + // var_dump($urlParams); + parent::render($urlParams, "home", "layouts/base"); + } catch (Exception $e) { + echo $e; + } + } + protected function post($urlParams) + { + try { + parent::put($urlParams); + } catch (Exception $e) { + echo $e; + } + } + protected function put($urlParams) + { + try { + parent::put($urlParams); + } catch (Exception $e) { + echo $e; + } + } + protected function delete($urlParams) + { + try { + parent::delete($urlParams); + } catch (Exception $e) { + echo $e; + } + } +} diff --git a/views/home.php b/views/home.php new file mode 100644 index 0000000000000000000000000000000000000000..86f9f5469140d769dca1e39c60942157332f801e --- /dev/null +++ b/views/home.php @@ -0,0 +1,5 @@ +<div> + <h1> + HOME + </h1> +</div> \ No newline at end of file diff --git a/views/layouts/base.php b/views/layouts/base.php index a81436628ee704d656ba217b034c1adbf3dc4835..3c98aee1fe0e8bc5ba8a52f530c17d56f2f5cf72 100644 --- a/views/layouts/base.php +++ b/views/layouts/base.php @@ -1 +1,26 @@ -<?php \ No newline at end of file +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <!-- <link rel="stylesheet" href="public/css/lib.css"> + <link rel="stylesheet" href="public/css/shared.css"> + <link rel="stylesheet" href="public/css/home.css"> --> + <!-- <title>Document</title> --> +</head> + +<body> + <nav> + + </nav> + + <main> + <h1>hai!!!</h1> + <?= $__content ?> + </main> + +</body> + +</html> \ No newline at end of file