-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
34 lines (24 loc) · 1.03 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require_once('./vendor/autoload.php');
use Blog\Controllers\ArticleController;
use Blog\Models\Article;
use Blog\Repositories\ArticleRepository;
use Blog\Services\ArticleService;
use Klein\Klein;
$templates = new League\Plates\Engine('views');
$articleService = new ArticleService(new ArticleRepository(new Article()));
// routes
$klein = new Klein();
$klein->respond('GET', '/', function () use ($templates, $articleService) {
$articles = (new ArticleController($articleService))->index();
echo $templates->render('articles', ['articles' => $articles]);
});
$klein->respond('GET', '/articles/[i:id]', function ($request) use ($templates, $articleService) {
$article = (new ArticleController($articleService))->show($request->id);
echo $templates->render('single-article', ['article' => $article]);
});
//todo: userService, userRepository to be implemented to get author data
$klein->respond('GET', '/authors/[i:id]', function ($request) use ($templates) {
echo $templates->render('single-author');
});
$klein->dispatch();