| | |
| | | } |
| | | |
| | | 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 |
| | |
| | | } |
| | | |
| | | 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" |
| | | ]); |
| | |
| | | |
| | | 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"]; |
| | |
| | | ]); |
| | | }; |
| | | } |
| | | |
| | | public function getProduct(string $id): array { |
| | | $product = $this->model->find($id); |
| | | if( $product == false ) { |
| | | throw new PageNotFoundException("Product not found"); |
| | | } |
| | | return $product; |
| | | } |
| | | } |