OKyJIucT
10/11/2016 - 9:54 AM

routes

routes

<?php

require __DIR__ . '/vendor/autoload.php';

session_start();

// Instantiate the app
$app = new \Slim\App();

$list = [
    '00001' => [
        'name' => 'Peter Jackson',
        'description' => 'Producer | Director',
        'image' => 'pjackson.jpg',
    ],
    '00002' => [
        'name' => 'Evangeline Lilly',
        'description' => 'Actress',
        'image' => 'elilly.jpg',
    ]
];

/* routes */
$app->get('/', function ($request, $response, $args) use ($list) {

    $response->write("Welcome: This is AlphansoTech Tutorial Guide");
    $response->withJson($list);

    return $response;
});

$app->get('/friends', function ($request, $response, $args) {

    $response->write("Hello Friends!");

    return $response;
});

$app->get('/friend/{id}', function ($request, $response, $args) use ($list) {

    $route = $request->getAttribute('route');
    $courseId = $route->getArgument('id');

    return getReturn($list[$courseId]);
});


$app->post('/test', function ($request, $response, $args) use ($list) {

    $data = $request->getParsedBody();

    return getReturn($data);
});

function getReturn($data)
{
    return json_encode($data);
}

// Run app
$app->run();