|
|
@@ -8,6 +8,8 @@ use Psr\Http\Message\ServerRequestInterface as Request; |
|
|
|
use Slim\Factory\AppFactory; |
|
|
|
use Blog\DB\User; |
|
|
|
use Blog\DB\Blog; |
|
|
|
use Blog\DB\Bloglist; |
|
|
|
use Blog\DB\DB; |
|
|
|
|
|
|
|
require __DIR__ . '/../vendor/autoload.php'; |
|
|
|
|
|
|
@@ -36,41 +38,26 @@ function addFooter($response) |
|
|
|
|
|
|
|
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]; |
|
|
|
$bloglist = new Bloglist; |
|
|
|
$articles = $bloglist->countBlogs(); |
|
|
|
$i = 0; |
|
|
|
$blogArray = []; |
|
|
|
while ($articles[$i]) { |
|
|
|
array_push($blogArray, $articles[$i]); |
|
|
|
$i++; |
|
|
|
} |
|
|
|
$_SESSION['blogs'] = $blogArray; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$app->get('/', function (Request $request, Response $response, array $args) { |
|
|
|
global $db; |
|
|
|
$sql = "SELECT * FROM blogs"; |
|
|
|
$sqlCount = "SELECT COUNT(id) FROM blogs"; |
|
|
|
$retCount = $db->query($sqlCount); |
|
|
|
$rows = $retCount->fetchArray(SQLITE3_ASSOC); |
|
|
|
$rowCount = $rows['count']; |
|
|
|
|
|
|
|
$ret = $db->query($sql); |
|
|
|
$blogArray1 = $ret->fetchArray(SQLITE3_ASSOC); |
|
|
|
$blogArray2 = $ret->fetchArray(SQLITE3_ASSOC); |
|
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i <= $rowCount; $i++) { |
|
|
|
$blogArray[$i] = $ret->fetchArray(SQLITE3_ASSOC); |
|
|
|
} |
|
|
|
// write fetchArray loop for every article |
|
|
|
|
|
|
|
if (!isset($_SESSION['blogs'])) { |
|
|
|
init(); |
|
|
|
} |
|
|
|
addNavbar($response); |
|
|
|
$response->getBody()->write('<hr/><h1>Onze blog</h1>'); |
|
|
|
$response->getBody()->write('<ul>'); |
|
|
|
// opdracht: lees de blogs in en toon een lijst met links naar artikels |
|
|
|
// commentaar fetchArray bekijken in documentatie voor loop tips |
|
|
|
|
|
|
|
foreach ($_SESSION['blogs'] as $art) { |
|
|
|
$response->getBody()->write('<li><a href="/blog/' . $art['slug'] . '">' . $art['title'] . '</a></li>'); |
|
|
@@ -129,6 +116,7 @@ $app->get('/blog/{slug}', function (Request $request, Response $response, array |
|
|
|
foreach ($_SESSION['blogs'] as $art) { |
|
|
|
if ($art['slug'] == $args['slug']) { |
|
|
|
$response->getBody()->write("<h1>" . $art['title'] . "</h1>"); |
|
|
|
$response->getBody()->write('<p>' . $art['content'] . '</p>'); |
|
|
|
} |
|
|
|
} |
|
|
|
|