corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-24 e99f0be8d819e5c71bfcdd0ccdf3c4d3758dd62d
src/App/Controllers/products.php
@@ -16,10 +16,8 @@
    }
    public function show(string $id) {
        $product = $this->model->find($id);
        if( $product == false ) {
            throw new PageNotFoundException("Product not found");
        }
        $product = $this->getProduct($id);
        echo $this->viewer->render("shared/header.php");
        echo $this->viewer->render("Products/show.php", [
            "product"=> $product
@@ -27,10 +25,8 @@
    }
    public function edit(string $id) {
        $product = $this->model->find($id);
        if( $product == false ) {
            throw new PageNotFoundException("Product not found");
        }
        $product = $this->getProduct($id);
        echo $this->viewer->render("shared/header.php", [
            "title"=> "Edit product"
        ]);
@@ -73,10 +69,7 @@
    public function update(string $id) {
        
        $product = $this->model->find($id);
        if( $product == false ) {
            throw new PageNotFoundException("Product not found");
        }
        $product = $this->getProduct($id);
        
        $product["name"] = $_POST["name"];
@@ -96,4 +89,12 @@
            ]);
        };
    }
    public function getProduct(string $id): array {
        $product = $this->model->find($id);
        if( $product == false ) {
            throw new PageNotFoundException("Product not found");
        }
        return $product;
    }
}