Created CV Section #6
@ -7,17 +7,31 @@ use Psr\Http\Message\ResponseInterface as Response;
|
|||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Slim\Factory\AppFactory;
|
use Slim\Factory\AppFactory;
|
||||||
|
|
||||||
require "routes.php";
|
//require “routes.php”;
|
||||||
require "./vendor/autoload.php";
|
require “../vendor/autoload.php”;
|
||||||
|
include "timelineData.php";
|
||||||
|
|
||||||
// Start slim
|
// Start slim
|
||||||
$app = AppFactory::create();
|
$app = AppFactory::create();
|
||||||
// create middleware
|
// create middleware
|
||||||
$app->addRoutingMiddleware();
|
$app->addRoutingMiddleware();
|
||||||
|
|
||||||
$errorMiddleware = $app->addErrorMiddleware(false, true, true);
|
// for error checking
|
||||||
|
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
|
||||||
|
|
||||||
$app->get("/timelineData", function (Request $request, Response $response)
|
$app->setBasePath(“/api”);
|
||||||
|
|
||||||
|
$timelineData = new TimelineData();
|
||||||
|
|
||||||
|
$app->get(“/timelineData”, function (Request $request, Response $response)
|
||||||
{
|
{
|
||||||
|
$result = $timelineData->getTimelineData();
|
||||||
|
|
||||||
|
$json = json_encode($result);
|
||||||
|
|
||||||
|
$response->getBody()->write($json);
|
||||||
|
|
||||||
|
return $response->withHeader("Content-Type", "application/json");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$app->run();1q
|
||||||
|
@ -1,7 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once "./confjg.php"
|
||||||
|
|
||||||
class TimelineData
|
class TimelineData
|
||||||
{
|
{
|
||||||
|
function getTimelineData()
|
||||||
|
{
|
||||||
|
$conn = dbConn();
|
||||||
|
$stmt = $conn->prepare("SELECT * FROM timeline;");
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
// set the resulting array to associative
|
||||||
|
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return array("errorMessage" => "Error timeline data not found");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user