aggiunta possibilità di vedere i singoli prodotti tramite /products/{numero}/show (parte 118)
| | |
| | | } |
| | | |
| | | 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 |
| | | ]); |
| | | } |
| | | |
| | |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | <body> |
| | | Show the product with ID <?= $id ?> here |
| | | <h1><?= $product["name"] ?></h1> |
| | | <p><?= $product["description"] ?></p> |
| | | </body> |
| | | |
| | | </html> |