1
0
Fork 0

Show images on index

This commit is contained in:
Ethanell 2020-10-16 11:57:47 +02:00
parent 8ebdd477a8
commit 4647018639
6 changed files with 44 additions and 4 deletions

View file

@ -3,4 +3,4 @@
$alert = choixAlert('url_non_valide');
//appel de la vue
require_once(PATH_VIEWS.$page.'php');
require_once(PATH_VIEWS.$page.'.php');

View file

@ -1 +1,8 @@
<?php
require_once(PATH_MODELS.$page.".php");
if (isset($photos) and $photos)
$alert = array("messageAlert" => count($photos)." photo(s) selectionnée(s)", "classAlert" => "success");
require_once(PATH_VIEWS.$page.'.php');

View file

@ -6,7 +6,6 @@ define('MENU_ACCUEIL','Accueil');
define('TEXTE_PAGE_404','Oops, la page demandée n\'existe pas !');
define('MESSAGE_ERREUR',"Une erreur s'est produite");
define('TITRE', '');
define("TITRE_PAGE_ACCUEIL_TOUS", "Toutes les photos");
define('TITRE', 'Mes photos');
define('ERREUR_QUERY', 'Problème d\'accès à la base de données. Contactez l\'administrateur');

11
lib/getPDD.php Normal file
View file

@ -0,0 +1,11 @@
<?php
function getPDO() {
try {
$bdd = new PDO("mysql:host=" . BD_HOST . ";dbname=" . BD_DBNAME . ";charset = utf8", BD_USER, BD_PWD);
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $bdd;
} catch (Exception $e) {
return $e;
}
}

18
models/m_accueil.php Normal file
View file

@ -0,0 +1,18 @@
<?php
require_once("lib/getPDD.php");
$bdd = getPDO();
if ($bdd instanceof PDO) {
try {
$req = $bdd->prepare("SELECT * FROM Photo");
$req->execute();
$photos = $req->fetchAll();
$req->closeCursor();
} catch (Exception $e) {
$alert = choixAlert("query");
}
} elseif ($bdd instanceof Exception)
$alert = choixAlert("query");

View file

@ -9,6 +9,11 @@
<!-- Début de la page -->
<h1><?= TITRE_PAGE_ACCUEIL_TOUS ?></h1>
<?php if(isset($photos) and $photos) {
foreach ($photos as $photo) {?>
<img src="<?= PATH_IMAGES ?>/<?= $photo['nomFich'] ?>" alt="<?= $photo['description'] ?>">
<?php }
} ?>
<!-- Fin de la page -->