-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
57 lines (47 loc) · 1.46 KB
/
bootstrap.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
* Project: Todo App
* Framework: Slim 3
* Helpers: Symfony VarDumper, Eloquent, Twig, Vue.js
*/
require '../vendor/autoload.php';
use \Slim\App;
use Illuminate\Database\Capsule\Manager as Capsule;
require '../config.php';
require '../app/Helpers/helper.php';
$app = new App([
'settings' => [
'displayErrorDetails' => true // Debug on
]
]);
// Eloquent Database instance
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => DB_HOST,
'port' => DB_PORT,
'database' => DB_NAME,
'username' => DB_USER,
'password' => DB_PASSWORD,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'
]);
$capsule->bootEloquent();
$capsule->setAsGlobal();
$container = $app->getContainer();
// Make Twig handle views
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig('../views', [
'cache' => '../cache'
]);
// Add base url to twig as an extension for easy use
$baseURL = rtrim(str_ireplace('index.php', '', $container->get('request')->getUri()->getHost() . $container->get('request')->getUri()->getBasePath()), '/');
$view->addExtension(new Slim\Views\TwigExtension($container->get('router'), $baseURL));
return $view;
};
// Custom 404 page
$container['notFoundHandler'] = function ($container) {
return function ($request, $response) use ($container) {
return $container['view']->render($response->withStatus(404), 'error/404.html.twig');
};
};