corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-23 47a5842b7eae4aa4fea971846957cd8889f41efd
src/App/Controllers/products.php
@@ -26,6 +26,19 @@
        ]);
    }
    public function edit(string $id) {
        $product = $this->model->find($id);
        if( $product == false ) {
            throw new PageNotFoundException("Product not found");
        }
        echo $this->viewer->render("shared/header.php", [
            "title"=> "Edit product"
        ]);
        echo $this->viewer->render("Products/edit.php", [
            "product"=> $product
        ]);
    }
    public function showPage(string $title, string $id, string $page) {
        echo $title, " ", $id, " ", $page;
    }
@@ -40,9 +53,20 @@
    public function create() {
        $data = [
            "name" => $_POST["name"],
            "description" => $_POST["description"]
            "description" => empty($_POST["description"]) ? null : $_POST["description"]
        ];
        var_dump($this->model->insert($data));
        if($this->model->insert($data)) {
            header("Location: /products/{$this->model->getInsertID()}/show");
            exit;
        } else {
            echo $this->viewer->render("shared/header.php", [
                "title" => "New Product"
            ]);
            echo $this->viewer->render("Products/new.php",
                ["errors" => $this->model->getErrors()
            ]);
        };
    }
}