|
|
@@ -11,10 +11,11 @@ use Psr\Http\Message\ResponseInterface as Response; |
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
|
|
|
use Slim\Factory\AppFactory; |
|
|
|
use Blog\DB\User; |
|
|
|
use Blog\DB\Blog as BlogDB; |
|
|
|
use Blog\Model\Blogs; |
|
|
|
use Blog\View\Twig; |
|
|
|
use Blog\DB\DB; |
|
|
|
use Blog\Model\Blogs; |
|
|
|
use Blog\Model\Menu; |
|
|
|
|
|
|
|
use Blog\Model\Blog; |
|
|
|
|
|
|
|
|
|
|
@@ -46,23 +47,15 @@ $container->set( |
|
|
|
|
|
|
|
function addNavbar($twig) |
|
|
|
{ |
|
|
|
$urls = [ |
|
|
|
["link" => "https://www.google.be", "name" => "Google"], |
|
|
|
["link" => "https://www.facebook.com", "name" => "Facebook"], |
|
|
|
["link" => "https://www.twiter.com", "name" => "Twitter"] |
|
|
|
]; |
|
|
|
$twig->addBlockVariable('navbar', $urls); |
|
|
|
$menu = new Menu('primary'); |
|
|
|
$twig->addBlockVariable('navbar', $menu->getLinks()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function addNavbar2($twig) |
|
|
|
{ |
|
|
|
$urls = [ |
|
|
|
["link" => "https://www.google.be", "name" => "Bing"], |
|
|
|
["link" => "https://www.facebook.com", "name" => "Apple"], |
|
|
|
["link" => "https://www.twiter.com", "name" => "TikTok"] |
|
|
|
]; |
|
|
|
$twig->addBlockVariable('navbar', $urls); |
|
|
|
$menu = new Menu('secondary'); |
|
|
|
$twig->addBlockVariable('navbar', $menu->getLinks()); |
|
|
|
} |
|
|
|
|
|
|
|
function addFooter($response) |
|
|
@@ -71,17 +64,10 @@ function addFooter($response) |
|
|
|
$response->getBody()->write("</body></html>"); |
|
|
|
return; |
|
|
|
} |
|
|
|
function init() |
|
|
|
{ |
|
|
|
$art1 = ["slug" => "artikel-1", "title" => "Dit is titel 1", "content" => "Lorem ipsum 1"]; |
|
|
|
$art2 = ["slug" => "artikel-2", "title" => "Dit is titel 2", "content" => "Lorem ipsum 2"]; |
|
|
|
$art3 = ["slug" => "artikel-3", "title" => "Dit is titel 3", "content" => "Lorem ipsum 3"]; |
|
|
|
$art4 = ["slug" => "artikel-4", "title" => "Dit is titel 4", "content" => "Lorem ipsum 4"]; |
|
|
|
$_SESSION['blogs'] = [$art1, $art2, $art3, $art4]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$app->get('/', function (Request $request, Response $response, array $args) { |
|
|
|
|
|
|
|
|
|
|
|
$blogs = new Blogs(); |
|
|
|
$blogs = $blogs->getBlogs(); |
|
|
|
|
|
|
@@ -141,15 +127,17 @@ $app->map(['GET', 'POST'], '/blog/create', function (Request $request, Response |
|
|
|
}); |
|
|
|
|
|
|
|
$app->get('/blog/{slug}', function (Request $request, Response $response, array $args) { |
|
|
|
$blogs = new Blogs(); |
|
|
|
$blogs = $blogs->getBlog($args['slug']); |
|
|
|
$vars = [ |
|
|
|
"content" => $blogs |
|
|
|
]; |
|
|
|
|
|
|
|
addNavbar($response); |
|
|
|
foreach ($_SESSION['blogs'] as $art) { |
|
|
|
if ($art['slug'] == $args['slug']) { |
|
|
|
$response->getBody()->write("<h1>" . $art['title'] . "</h1>"); |
|
|
|
} |
|
|
|
} |
|
|
|
$twig = $this->get('twig'); |
|
|
|
addNavbar($twig); |
|
|
|
$a = $twig->render('blog.html.twig', $vars); |
|
|
|
$response->getBody()->write($a); |
|
|
|
|
|
|
|
addFooter($response); |
|
|
|
return $response; |
|
|
|
}); |
|
|
|
|