From 00e0e78a7f4830bf94758ab991efc5c2aa331dc2 Mon Sep 17 00:00:00 2001
From: filippo.bertilotti <filippobertilotti@gmail.com>
Date: Mon, 06 May 2024 09:49:09 +0200
Subject: [PATCH] refactor codice utilizzando la classe Model (parte 10)

---
 index.php |   29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/index.php b/index.php
index 2ca28b7..cbca938 100644
--- a/index.php
+++ b/index.php
@@ -1,12 +1,21 @@
 <?php
-    $dns = "mysql:host=localhost;dbname=product_db;charset=utf8;port=3306";
-    $pdo = new PDO($dns, "product_db_user", "secret", [
-        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
-    ]);
+    require "model.php";
+    $model = new Model;
+    $products = $model->getData();
+?>
 
-    $stmt = $pdo->query("SELECT * FROM product");
-
-    $products = $stmt->fetchAll(PDO::FETCH_ASSOC);
-    
-    print_r($products);
-?>
\ No newline at end of file
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Products</title>
+</head>
+<body>
+    <h1>Products</h1>
+    <?php foreach ($products as $product): ?>
+        <h2><?= htmlspecialchars($product["name"]) ?></h2>
+        <p><?= htmlspecialchars($product["description"]) ?></p>
+    <?php endforeach; ?>
+</body>
+</html>
\ No newline at end of file

--
Gitblit v1.8.0