From f3f2a6502b52095069459086d309d9788277e6d7 Mon Sep 17 00:00:00 2001 From: Ro Date: Fri, 26 Mar 2021 20:24:16 -0700 Subject: [PATCH] normalized url routing and cleaned up templating structure --- brain/controller/DashControl.inc.php | 28 ++++++-- brain/controller/IndexControl.inc.php | 27 ++++--- brain/controller/RouteControl.inc.php | 31 ++++++++ brain/views/dash/{frame.twig => _frame.twig} | 0 brain/views/dash/start.twig | 2 +- brain/views/front/_frame.twig | 37 ++++++++++ brain/views/front/start.twig | 17 +++++ index.php | 74 ++------------------ 8 files changed, 133 insertions(+), 83 deletions(-) create mode 100644 brain/controller/RouteControl.inc.php rename brain/views/dash/{frame.twig => _frame.twig} (100%) create mode 100644 brain/views/front/_frame.twig diff --git a/brain/controller/DashControl.inc.php b/brain/controller/DashControl.inc.php index db89ec5..0315dba 100644 --- a/brain/controller/DashControl.inc.php +++ b/brain/controller/DashControl.inc.php @@ -1,18 +1,36 @@ getContents(); + $book = new Book("content/pages"); + $pageOptions = [ + "title" => "Fipamo Dashboard", + "status" => $auth->sessionStatus(), + "pages" => $book->getContents(), + ]; break; } + + return $view->render($response, "dash/start.twig", $pageOptions); } } diff --git a/brain/controller/IndexControl.inc.php b/brain/controller/IndexControl.inc.php index 1bd56c2..039f72a 100644 --- a/brain/controller/IndexControl.inc.php +++ b/brain/controller/IndexControl.inc.php @@ -1,12 +1,23 @@ secret; - } - -} \ No newline at end of file + public static function start( + ServerRequestInterface $request, + ResponseInterface $response, + array $args + ): ResponseInterface { + $view = Twig::fromRequest($request); + + return $view->render($response, "front/start.twig", [ + "title" => "Fipamo Dash", + "status" => false, + "pages" => [], + "totalPages" => 0, + ]); + } +} diff --git a/brain/controller/RouteControl.inc.php b/brain/controller/RouteControl.inc.php new file mode 100644 index 0000000..93550b8 --- /dev/null +++ b/brain/controller/RouteControl.inc.php @@ -0,0 +1,31 @@ + + + + + + {% block title %} + {{ title }} + {% endblock %} + + {% block stylesheets %}{% endblock %} + + +
{% block mainContent %}{% endblock %} + + + +
+ + +{% block javascripts %}{% endblock %} \ No newline at end of file diff --git a/brain/views/front/start.twig b/brain/views/front/start.twig index e69de29..c3fb820 100644 --- a/brain/views/front/start.twig +++ b/brain/views/front/start.twig @@ -0,0 +1,17 @@ +{% extends "front/_frame.twig" %} + +{% block title %} + {{ title }} +{% endblock %} + +{% block stylesheets %} + + {% endblock %} + + {% block mainContent %} + This is the index page, boss + {% endblock %} + + {% block javascripts %} + + {% endblock %} \ No newline at end of file diff --git a/index.php b/index.php index aad022f..1851f0f 100644 --- a/index.php +++ b/index.php @@ -7,78 +7,14 @@ use Slim\Factory\AppFactory; use Slim\Views\Twig; use Slim\Views\TwigMiddleware; -include "brain/controller/IndexControl.inc.php"; -include "brain/controller/DashControl.inc.php"; -include "brain/data/Auth.inc.php"; +include "brain/controller/RouteControl.inc.php"; $app = AppFactory::create(); $twig = Twig::create("brain/views/"); $app->add(TwigMiddleware::create($app, $twig)); -//Index -$app->get("/[{first}[/{second}]]", function ( - Request $request, - Response $response, - array $args -) { - $view = Twig::fromRequest($request); - if (isset($args["first"])) { - $first = $args["first"]; - if (is_numeric($first)) { - $response->getBody()->write("FIND A PAGE, B!"); - } else { - //$response->getBody()->write("This is the dash, brah!"); - - if ($first == "dashboard") { - if (isset($args["second"])) { - $section = $args["second"]; - } else { - $section = "index"; - } - - $dash = new DashControl(); - $pages = $dash->getPages($section); - - $count = count($pages); - - //$response->getBody()->write("There are " . $count . " pages, champ"); - $auth = new Auth(); - return $view->render($response, "dash/start.twig", [ - "title" => "Fipamo Dash", - "status" => $auth->sessionStatus(), - "pages" => $pages, - "totalPages" => $count, - ]); - } else { - } - } - } else { - $response->getBody()->write("No Params, Homie!"); - } - - if (isset($args["second"])) { - $year = $args["second"]; - } - - return $response; -}); - -//Dashboard Index -/** -$app->get('/@/dashboard', function (Request $request, Response $response) { - $index = new IndexControl(); - $settings = new Settings(); - $folks = $settings->getFolks(); - $secret = $index->getSecret(); - $view = Twig::fromRequest($request); - - return $view->render($response, 'index.twig', [ - 'title' => 'This is Fipamo', - 'name' => 'Ro', - 'occupation'=>'pretty cool... I guess', - 'folks' => $folks[0]['handle'], - 'secret' => $secret - ]); -}); -**/ +//set up routing +$app->get("/[{first}[/{second}[/{third}]]]", "\RouteControl:get"); +$app->post("/[{first}[/{second}[/{third}]]]", "\RouteControl:post"); +//start the app $app->run();