corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-20 e45454a4f7863d0c8f0d92b589e90f9ad067584e
aggiunta possibilità di vedere i singoli prodotti tramite /products/{numero}/show (parte 118)
3 files modified
17 ■■■■ changed files
src/App/Controllers/products.php 3 ●●●● patch | view | raw | blame | history
src/App/Models/product.php 11 ●●●●● patch | view | raw | blame | history
views/Products/show.php 3 ●●●● patch | view | raw | blame | history
src/App/Controllers/products.php
@@ -15,9 +15,10 @@
    }
    public function show(string $id) {
        $product = $this->model->find($id);
        echo $this->viewer->render("shared/header.php");
        echo $this->viewer->render("Products/show.php", [
            "id"=> $id
            "product"=> $product
        ]);
    }
src/App/Models/product.php
@@ -16,6 +16,17 @@
            return $stmt->fetchAll(PDO::FETCH_ASSOC);
        }
        public function find(string $id) {
            $conn = $this->database->getConnection();
            $sql = "SELECT *
                    FROM product
                    WHERE id = :id";
            $stmt = $conn->prepare($sql);
            $stmt->bindValue(":id", $id, PDO::PARAM_INT);
            $stmt->execute();
            return $stmt->fetch(PDO::FETCH_ASSOC);
        }
    }
views/Products/show.php
@@ -1,5 +1,6 @@
<body>
    Show the product with ID <?= $id ?> here
    <h1><?= $product["name"] ?></h1>
    <p><?= $product["description"] ?></p>
</body>
</html>