示例#1
0
<?php

// start setup
require "../vendor/autoload.php";
spl_autoload_register(function ($classname) {
    include __DIR__ . "/../lib/" . $classname . ".php";
});
define('API_URL', 'http://localhost:8880/');
$app = new \Slim\Slim(array("templates.path" => __DIR__ . '/../templates/'));
// end setup
session_start();
// start events list
$app->get('/', function () use($app) {
    $client = new ApiClient(new GuzzleHttp\Client(), API_URL);
    $events = $client->getEventList();
    $app->render("index.php", array("events" => $events));
});
// end events list
$app->get('/showEvent/:event_id', function ($event_id) use($app) {
    $client = new ApiClient(new GuzzleHttp\Client(), API_URL);
    $events = $client->getEvent($event_id);
    $app->render("detail.php", array("events" => $events));
});
$app->get('/login', function () use($app) {
    $app->render("login.php");
});
$app->post('/login', function () use($app) {
    $password = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING);
    $username = filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING);
    $client = new ApiClient(new GuzzleHttp\Client(), API_URL);
    $access_token = $client->getAccessToken($username, $password);