| | |
| | | <?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->getData(); |
| | | $products = $this->model->findAll(); |
| | | |
| | | echo $this->viewer->render("shared/header.php"); |
| | | echo $this->viewer->render("Products/index.php", [ |
| | |
| | | |
| | | public function show(string $id) { |
| | | $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 |