Esempio n. 1
0
// Delete Employee
$app->get('/employee/{id}/delete', function ($request, $response, $args) {
    $id = (int) $args['id'];
    $mapper = new EmployeeMapper($this->db);
    $employee = $mapper->getEmployeeById($id);
    $this->logger->info("Deleting employee " . $employee->getName());
    $mapper->delete($employee);
    $response = $response->withRedirect("/index.php/employees");
    return $response;
});
/**********************ITEMS**********************/
// Items
$app->get('/items', function ($request, $response, $args) {
    $this->logger->info("Items page");
    $item_mapper = new ItemMapper($this->db);
    $items = $item_mapper->getItems();
    return $this->renderer->render($response, 'item/items.phtml', [$args, "items" => $items]);
});
// New Item
$app->get('/item/new', function ($request, $response, $args) {
    $this->logger->info("Creating new item");
    $mapper = new ColorMapper($this->db);
    $colors = $mapper->getColors();
    return $this->renderer->render($response, 'item/item.phtml', [$args, "colors" => $colors]);
});
// New Item POST
$app->post('/item/new', function ($request, $response) {
    $post_data = $request->getParsedBody();
    $data = [];
    $data['Name'] = filter_var($post_data['name'], FILTER_SANITIZE_STRING);
    $data['Color'] = filter_var($post_data['color'], FILTER_SANITIZE_STRING);