-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
40 lines (27 loc) · 941 Bytes
/
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
<?php
ini_set('display_errors',1);
/* PDO */
$pdo=new PDO('mysql:host=localhost;dbname=livres','root','chuvanan');
$req = $pdo->prepare("SELECT * FROM livre");
$req->execute();
$livres = $req->fetchAll(PDO::FETCH_ASSOC);
var_dump($livres);
require_once __DIR__ .'/vendor/autoload.php'; /* De include autoload, su dung cac classe, __DIR__ se la Ontwig */
$loader = new Twig_Loader_Filesystem (__DIR__ . '/templates');
$twig= new Twig_Environment ($loader);
$page= isset( $_GET['page']) ? $_GET['page'] :null; // neu khong co trang nao thi se la null, tra ve index.html
switch ($page) {
case 'apropos':
echo $twig->render('pages/apropos.html.twig', array('name' => 'Nhat'));
break;
case 'contact':
echo $twig->render('pages/contact.html.twig');
break;
case 'livres':
echo $twig->render('pages/livres.html.twig',['livres'=>$livres]);
break;
default:
echo $twig->render('pages/index.html.twig');
break;
}
?>