public function actionCreate() { $errors = []; $categories = CategoryModel::getAll(false, true); $product = new ProductModel(); if (isset($_POST['submit'])) { $name = FL::clearStr($_POST['name']); $categoryId = FL::clearInt($_POST['category_id']); $code = FL::clearInt($_POST['code']); $price = FL::clearFloat($_POST['price']); $availability = FL::clearInt($_POST['availability']); $brand = FL::clearStr($_POST['brand']); $description = FL::clearStr($_POST['description']); $isNew = FL::clearInt($_POST['is_new']); $isRecommended = FL::clearInt($_POST['is_recommended']); $status = FL::clearInt($_POST['status']); if (!FL::isValue($name)) { $errors[] = 'Название не может быть пустым'; } if (empty($errors)) { $product->name = $name; $product->categoryId = $categoryId; $product->code = $code; $product->price = $price; $product->availability = $availability; $product->brand = $brand; $product->description = $description; $product->isNew = $isNew; $product->isRecommended = $isRecommended; $product->status = $status; $id = $product->save(); if (!$id) { $errors[] = 'Произошла ошибка'; } else { FL::redirectTo('/admin/product'); } } } $view = new View(); $view->categories = $categories; $view->errors = $errors; $view->display('admin_product/create.php'); return true; }