corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-21 766451d7a969ca8b6b80d7da206ef76e3f376925
src/App/Controllers/products.php
@@ -1,21 +1,29 @@
<?php
namespace App\Controllers;
use App\Models\Product;
use Framework\Exceptions\PageNotFoundException;
use Framework\Viewer;
class Products {
    public function __construct(private Viewer $viewer, private Product $model) { }
    public function index() {
        $products = $this->model->findAll();
        $model = new Product;
        $products = $model->getData();
        $viewer = new Viewer;
        require "views/products_index.php";
        echo $this->viewer->render("shared/header.php");
        echo $this->viewer->render("Products/index.php", [
            "products"=> $products
        ]);
    }
    public function show(string $id) {
        var_dump($id);
        require "views/products_show.php";
        $product = $this->model->find($id);
        if( $product == false ) {
            throw new PageNotFoundException("Product not found");
        }
        echo $this->viewer->render("shared/header.php");
        echo $this->viewer->render("Products/show.php", [
            "product"=> $product
        ]);
    }
    public function showPage(string $title, string $id, string $page) {