예제 #1
0
<?php

// Routes
$app->get('/', function ($request, $response, $args) {
    // Sample log message
    $this->logger->info("Home");
    // Render index view
    return $this->renderer->render($response, 'index.phtml', $args);
});
/**********************CUSTOMERS**********************/
// Customers
$app->get('/customers', function ($request, $response, $args) {
    $this->logger->info("Customers page");
    $customer_mapper = new CustomerMapper($this->db);
    $customers = $customer_mapper->getCustomers();
    return $this->renderer->render($response, 'customer/customers.phtml', [$args, "customers" => $customers]);
});
// New Customer
$app->get('/customer/new', function ($request, $response, $args) {
    $this->logger->info("Creating new customer");
    return $this->renderer->render($response, 'customer/customer.phtml', $args);
});
// New Customer POST
$app->post('/customer/new', function ($request, $response) {
    $this->logger->info("POST Creating new customer");
    $post_data = $request->getParsedBody();
    $customer_data = [];
    $customer_data['Name'] = filter_var($post_data['name'], FILTER_SANITIZE_STRING);
    $customer_data['Address'] = filter_var($post_data['address'], FILTER_SANITIZE_STRING);
    $customer_data['Telephone'] = filter_var($post_data['phone'], FILTER_SANITIZE_STRING);
    $customer = new CustomerEntity($customer_data);