normalized url routing and cleaned up templating structure

beta
Ro 4 years ago
parent cf752fd8c0
commit f3f2a6502b

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

@ -1,12 +1,23 @@
<?php <?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Views\Twig;
class IndexControl class IndexControl
{ {
private $secret = 'not very secretish'; public static function start(
ServerRequestInterface $request,
ResponseInterface $response,
array $args
): ResponseInterface {
$view = Twig::fromRequest($request);
public function getSecret() return $view->render($response, "front/start.twig", [
{ "title" => "Fipamo Dash",
return $this->secret; "status" => false,
"pages" => [],
"totalPages" => 0,
]);
} }
} }

@ -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 {
}
}

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

@ -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>

@ -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 %}

@ -7,78 +7,14 @@ use Slim\Factory\AppFactory;
use Slim\Views\Twig; use Slim\Views\Twig;
use Slim\Views\TwigMiddleware; use Slim\Views\TwigMiddleware;
include "brain/controller/IndexControl.inc.php"; include "brain/controller/RouteControl.inc.php";
include "brain/controller/DashControl.inc.php";
include "brain/data/Auth.inc.php";
$app = AppFactory::create(); $app = AppFactory::create();
$twig = Twig::create("brain/views/"); $twig = Twig::create("brain/views/");
$app->add(TwigMiddleware::create($app, $twig)); $app->add(TwigMiddleware::create($app, $twig));
//Index //set up routing
$app->get("/[{first}[/{second}]]", function ( $app->get("/[{first}[/{second}[/{third}]]]", "\RouteControl:get");
Request $request, $app->post("/[{first}[/{second}[/{third}]]]", "\RouteControl:post");
Response $response, //start the app
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
]);
});
**/
$app->run(); $app->run();

Loading…
Cancel
Save