Skip to content

Instantly share code, notes, and snippets.

@Davisonpro
Last active August 9, 2023 19:54
Show Gist options
  • Save Davisonpro/e89659c21dcfba5d5d2fce5d848faa7f to your computer and use it in GitHub Desktop.
Save Davisonpro/e89659c21dcfba5d5d2fce5d848faa7f to your computer and use it in GitHub Desktop.
<?php
require dirname(__FILE__) . '/vendor/autoload.php';
require dirname(__FILE__) . '/controllers/TodoController.php';
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteCollectorProxy;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;
use Slim\Factory\AppFactory;
define("BASEPATH", '/php-react');
define("DB_NAME", 'todo_app');
define("DB_USER", 'root');
define("DB_PASSWORD", 'password');
define("DB_HOST", 'localhost');
$app = AppFactory::create();
$app->setBasePath(BASEPATH);
$app->addRoutingMiddleware();
$app->addBodyParsingMiddleware();
$twig = Twig::create('views', ['cache' => false]);
// Add Twig-View Middleware
$app->add(TwigMiddleware::create($app, $twig));
$app->get('/', function (Request $request, Response $response, $args) {
$view = Twig::fromRequest($request);
return $view->render($response, 'index.html');
});
$app->group('/api', function (RouteCollectorProxy $group) {
$group->get('/todos', 'TodoController:getTodos');
$group->post('/todos', 'TodoController:addTodo');
$group->put('/todos/{id}', 'TodoController:updateTodo');
$group->delete('/todos/{id}', 'TodoController:deleteTodo');
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment