-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
76 lines (64 loc) · 2.13 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
$config = [
'displayErrorDetails' => true,
'determineRouteBeforeAppMiddleware' => true,
'addContentLengthHeader' => false,
];
$config['db'] = include 'db_config.php';
// Create app
$app = new \Slim\App(["settings" => $config]);
// Get container
$container = $app->getContainer();
// Register component on container
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig('views', [
'debug' => true,
'cache' => false
]);
$view->addExtension(new \Slim\Views\TwigExtension(
$container['router'],
$container['request']->getUri()
));
$view->addExtension(new Twig_Extension_Debug());
return $view;
};
$container['db'] = function ($c) {
$db = $c['settings']['db'];
try {
$pdo = new PDO("mysql:host=" . $db['host'] . ";dbname=" . $db['dbname'], $db['user'], $db['pass']);
// $pdo = new PDO("sqlsrv:Server=" . $db['host'] . ";Database=" . $db['dbname']);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
die();
}
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_PERSISTENT, true);
return $pdo;
};
$app->add(new \RKA\SessionMiddleware());
// $app->add(new \Lib\Middlewares\CheckSession());
$container['LoginCtrl'] = function ($container) {
return new \Lib\Controllers\LoginCtrl($container);
};
$container['SchoolCtrl'] = function ($container) {
return new \Lib\Controllers\SchoolCtrl($container);
};
$container['AdministrationCtrl'] = function ($container) {
return new \Lib\Controllers\AdministrationCtrl($container);
};
$container['CourseCtrl'] = function ($container) {
return new \Lib\Controllers\CourseCtrl($container);
};
$container['StudentCtrl'] = function ($container) {
return new \Lib\Controllers\StudentCtrl($container);
};
$container['AdminCtrl'] = function ($container) {
return new \Lib\Controllers\AdminCtrl($container);
};
require 'lib/routes.php';
$app->run();