public function create() { $data = array(); $insertInfo = array('name' => '', 'description' => ''); $errors = array(); if (isset($_POST['createCategory'])) { 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)) { $insertInfo['name'] = $_POST['name']; $insertInfo['description'] = $_POST['description']; $table = 'categories'; $categoryEntity = new CategoryEntity(); $obj = $categoryEntity->init($insertInfo); $categoryCollection = new CategoryCollection(); $categoryCollection->save($obj); header('Location: index.php?c=category&m=index'); } } $data['errors'] = $errors; $data['insertInfo'] = $insertInfo; $this->loadView('category/create', $data); }
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); $categoryCollection->save($obj); $_SESSION['flashMessage'] = 'You have 1 affected row'; header('Location: categories.php'); } } ?> <?php require_once 'common/sidebar.php'; ?> <!-- start: Content --> <div id="content" class="span10">