-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
30 lines (25 loc) · 1.35 KB
/
index.php
File metadata and controls
30 lines (25 loc) · 1.35 KB
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
<?php
// мы используем сессию для хранения токена
// не забываем стартовать сессию в самом начале
session_start();
// подключаем файл с основными функциями
require 'vendor/autoload.php';
// получаем название контроллера из адресной строки
// http://localhost/index.php?action=message&method=add
// если там пусто - по умолчанию это будет 'home'
$action = isset($_GET['action']) ? strtolower($_GET['action']) . 'Controller' : 'AccountController';
$action = ucwords($action);
$method = isset($_GET['method']) ? $_GET['method'] : 'index';
// формируем название нужного файла контроллера
// в папке controllers должен быть файл php
// с названием, соответствующим пришедшему из адресной строки
$action_file = 'controllers/' . $action . '.php';
// проверяем есть ли такой файл и подключаем его
// иначе выводим шаблон с сообщением об ошибке
if (file_exists($action_file)) {
require $action_file;
$controller = new $action();
$controller->$method();
} else {
echo template('templates/error.php');
}