<?php $sub_categoryManager = new SubCategoryManager($db); try { $sub_category = $sub_categoryManager->findById($_GET['id']); } catch (Exception $e) { $sub_category = $e->getMessage(); } if (!is_string($sub_category)) { require 'views/sub_category.phtml'; } else { echo "Nothing to show"; }
<?php if (isset($_GET['page'])) { if ($_GET['page'] == 'create_product') { $name = $description = $price = $img = $stock = ""; if (isset($_POST['name'], $_POST['description'], $_POST['price'], $_POST['img'], $_POST['stock'], $_POST['subCategory_category'])) { $productManager = new ProductManager($db); $subCategoryManager = new SubCategoryManager($db); try { $subCategory = $subCategoryManager->findById($_POST['subCategory_category']); } catch (Exception $e) { $errors[] = $e->getMessage(); } $product = $productManager->create($subCategory, $_POST['name'], $_POST['description'], $_POST['price'], $_POST['img'], $_POST['stock']); if (is_array($product)) { $errors = array_merge($errors, $product); $name = $_POST['name']; $description = $_POST['description']; $price = $_POST['price']; $img = $_POST['img']; $stock = $_POST['stock']; } else { $_SESSION['success'] = "Produit créé avec succès"; header('Location: ?page=product&id=' . $product->getId()); exit; } } } }