-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainController.php
72 lines (48 loc) · 1.35 KB
/
MainController.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
<?php
class MainController {
public function insertPost() {
}
public function home() {
// Récupérer les 10 derniers posts
$postManager = new PostManager();
$posts = $postManager->findLatest();
// faire un include du fichier HTML
include("page/home.php");
}
public function showPost() {
$postManager = new PostManager();
$id = $_GET['id'];
$post = $postManager->findPostById($id);
include("page/detailPost.php");
}
public function createPost() {
$post = new Post();
if(!empty($_POST)) {
$post->setTitle($_POST['title']);
$post->setContent($_POST['content']);
$post->setUsername($_POST['username']);
$post->setEmail($_POST['email']);
$validator = new Validator();
$validator->validateEmail($post->getEmail(), 'email');
if($validator->isValid()) {
$postManager = new PostManager();
if($postManager->save($post)) {
header('Location: '.Config::ROOT_URL.'home');
die();
} else {
$error = "Une erreur est intervenue";
header('Location: '.Config::ROOT_URL.'createPost');
die();
}
} else {
$error = "Une erreur est intervenue";
header('Location: '.Config::ROOT_URL.'createPost');
die();
}
}
include("page/createPost.php");
}
public function verifPost() {
include("verif/verifPost.php");
}
}