corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-21 766451d7a969ca8b6b80d7da206ef76e3f376925
commit | author | age
026ec0 1 <?php
c042bc 2 namespace App\Controllers;
5cc38b 3 use App\Models\Product;
ce9b21 4 use Framework\Exceptions\PageNotFoundException;
157da9 5 use Framework\Viewer;
c54720 6 class Products {
f5ed86 7     public function __construct(private Viewer $viewer, private Product $model) { }
026ec0 8     public function index() {
ed1f74 9         
ce9b21 10         $products = $this->model->findAll();
026ec0 11
f76104 12         echo $this->viewer->render("shared/header.php");
F 13         echo $this->viewer->render("Products/index.php", [
6a2226 14             "products"=> $products
F 15         ]);
026ec0 16     }
2e7bc3 17
a93a2f 18     public function show(string $id) {
e45454 19         $product = $this->model->find($id);
ce9b21 20         if( $product == false ) {
F 21             throw new PageNotFoundException("Product not found");
22         }
f76104 23         echo $this->viewer->render("shared/header.php");
F 24         echo $this->viewer->render("Products/show.php", [
e45454 25             "product"=> $product
8fdeaa 26         ]);
2e7bc3 27     }
1f822b 28
F 29     public function showPage(string $title, string $id, string $page) {
1e5093 30         echo $title, " ", $id, " ", $page;
1f822b 31     }
026ec0 32 }