public function delete() { if (!$this->loggedIn()) { header('Location: index.php?c=login&m=login'); } if (!isset($_GET['id'])) { header('Location: index.php?c=category&m=index'); } $categoryCollection = new CategoryCollection(); $category = $categoryCollection->getOne($_GET['id']); if (is_null($category)) { header('Location: index.php?c=category&m=index'); } $categoryCollection->delete($category->getId()); header('Location: index.php?c=category&m=index'); }
<?php require_once 'common/header.php'; if (!loggedIn()) { header('Location: login.php'); } if (!loggedIn()) { header('Location: login.php'); } if (!isset($_GET['id'])) { header('Location: clients.php'); } $categoryCollection = new CategoryCollection(); $category = $categoryCollection->getOne($_GET['id']); if (is_null($category)) { header('Location: categories.php'); } $insertInfo = array('name' => $category->getName(), 'description' => $category->getDescription()); $errors = array(); if (isset($_POST['editCategory'])) { $insertInfo = array('name' => isset($_POST['name']) ? $_POST['name'] : '', 'description' => isset($_POST['description']) ? $_POST['description'] : ''); if (!isset($_POST['name']) || strlen($_POST['name']) < 3 || strlen($_POST['name']) > 255) { $errors['name'] = 'Incorrect name'; } if (!isset($_POST['description']) || strlen($_POST['description']) < 3 || strlen($_POST['description']) > 255) { $errors['description'] = 'Incorrect description'; } if (empty($errors)) { $categoryEntity = new CategoryEntity(); $categoryEntity->setId($_GET['id']); $obj = $categoryEntity->init($insertInfo);