normalized url routing and cleaned up templating structure

This commit is contained in:
Ro 2021-03-26 20:24:16 -07:00
parent cf752fd8c0
commit f3f2a6502b
8 changed files with 133 additions and 83 deletions

View file

@ -1,18 +1,36 @@
<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Views\Twig;
include "brain/data/Book.inc.php";
include "brain/data/Auth.inc.php";
class DashControl
{
public function getPages($section)
{
$book = new Book("content/pages");
switch ($section) {
public static function start(
ServerRequestInterface $request,
ResponseInterface $response,
array $args
): ResponseInterface {
$view = Twig::fromRequest($request);
$pageOptions = [];
$auth = new Auth();
switch (isset($args["second"]) ? $args["second"] : "index") {
case "pages":
$content = [];
break;
default:
return $book->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);
}
}

View file

@ -1,12 +1,23 @@
<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Views\Twig;
class IndexControl
{
private $secret = 'not very secretish';
public function getSecret()
{
return $this->secret;
}
}
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,
]);
}
}

View file

@ -0,0 +1,31 @@
<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
include "brain/controller/IndexControl.inc.php";
include "brain/controller/DashControl.inc.php";
class RouteControl
{
public function get(
ServerRequestInterface $request,
ResponseInterface $response,
array $args
): ResponseInterface {
switch (isset($args["first"]) ? $args["first"] : "index") {
case "dashboard":
return DashControl::start($request, $response, $args);
break;
default:
return IndexControl::start($request, $response, $args);
break;
}
}
public function post(
ServerRequestInterface $request,
ResponseInterface $response,
array $args
): ResponseInterface {
}
}

View file

@ -1,4 +1,4 @@
{% extends "dash/frame.twig" %}
{% extends "dash/_frame.twig" %}
{% block title %}
{{ title }}

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
{% block title %}
{{ title }}
{% endblock %}
</title>
{% block stylesheets %}{% endblock %}
</head>
<body>
<div id="main-content" class="main-container"> {% block mainContent %}{% endblock %}
</section>
</body>
</html>
</div>
<footer>
{% if options['showFooter'] is defined %}
<!-- NO FOOTER -->
{% else %}
<div class="inner">
<div class="columns">
<div id="footer_left" class="column">
<a href="#">About</a><br/>
</div>
<div id="footer_right " class="column">
<a href="#">FAQ</a><br/>
</div>
</div>
</div>
{% endif %}
</footer>
{% block javascripts %}{% endblock %}</body></html>

View file

@ -0,0 +1,17 @@
{% extends "front/_frame.twig" %}
{% block title %}
{{ title }}
{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/public/assets/css/base.css">
{% endblock %}
{% block mainContent %}
This is the index page, boss
{% endblock %}
{% block javascripts %}
<script src="/public/assets/scripts/dash.min.js" type="text/javascript"></script>
{% endblock %}

View file

@ -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();