Skip to content
Snippets Groups Projects
Commit ffea0dfb authored by Kenneth Ezekiel's avatar Kenneth Ezekiel
Browse files

feat: Layouting

parent 0d5f031e
No related merge requests found
......@@ -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";
}
}
<?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;
}
}
}
<div>
<h1>
HOME
</h1>
</div>
\ No newline at end of file
<?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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment