Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"autoload": {
"psr-4": {
"my\\namespace\\" : "src"
"Davian\\apilabtemplate\\" : "src"
}
}
}
23 changes: 23 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response; //This allows us to use the Request and Response objects in our code

require './vendor/autoload.php'; //It allows you to automatically pull in scripts and classes without having to do it manually
$app = new \apilabtemplate\App; //$app is our instance of slim
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
//{name} in the url indicates what the argument will be called
//Line 9; adds the text "Hello, $name" to the response

$container = $app->getContainer();
$container['logger'] = function($c) {
$logger = new \Monolog\Logger('my_logger');
$file_handler = new \Monolog\Handler\StreamHandler('../logs/app.log');
$logger->pushHandler($file_handler);
return $logger;
}; //This creates a new directory 'logs' in the firstSlim directory
//Creates and writes to app.log file in that directory.
$app->run(); //This tells PHP to run the slim app