Bläddra i källkod

created services twig and db

Services
Ruben De Baets 2 år sedan
förälder
incheckning
689c7866bd
1 ändrade filer med 24 tillägg och 4 borttagningar
  1. 24
    4
      public/index.php

+ 24
- 4
public/index.php Visa fil

@@ -6,26 +6,44 @@ namespace Blog;

session_start();

use DI\Container;
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;
use Blog\View\Twig;
use Blog\DB\DB;

require __DIR__ . '/../vendor/autoload.php';

$twig = new Twig('../templates');

addNavbar();

#addNavbar();

$container = new Container();
AppFactory::setContainer($container);
$app = AppFactory::create();



$container->set('twig', function () {
$twig = new Twig('../templates');
return $twig;
});

$container->set(
'db',
function () {
$db = new DB();
return $db;
}
);


function addNavbar()
{
global $twig;
$twig = $this->get('twig');

$urls = [
["link" => "https://www.google.be", "name" => "Google"],
@@ -63,8 +81,10 @@ $app->get('/', function (Request $request, Response $response, array $args) {
"content" => "Dit is de main body met info"
];

global $twig;
$twig = $this->get('twig');

$err = ['type' => 'error', 'text' => "something's wrong"];

$twig->addMessage($err);
$a = $twig->render('index.html.twig', $vars);
$response->getBody()->write($a);

Laddar…
Avbryt
Spara