Skip to content

Instantly share code, notes, and snippets.

@nicklaw5
Created February 24, 2017 23:58
Show Gist options
  • Save nicklaw5/6b684815a2ca86066819ddc79615ee15 to your computer and use it in GitHub Desktop.
Save nicklaw5/6b684815a2ca86066819ddc79615ee15 to your computer and use it in GitHub Desktop.
slim example

directory structure:

/my-project
  /public
     index.php
  /src
     /Controllers
        UsersController.php
  /test
  /vendor

composer.json:

{
    "require": {
        "php": ">=7.0",
        "slim/slim": "^3.0"
    },
    "autoload": {
        "psr-4": {
            "Yornus\\": "scr/",
        }
    }
}

index.php:

<?php

use \Yornus\Controllers\UsersController;

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

$app = new \Slim\App([
    'settings' => [
        'displayErrorDetails' => true,
    ],
]);

$app->get('/', UsersController::class, ':index');

$app->run();

UsersController.php:

<?php

namespace Yornus\Controllers;

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

class UsersController
{
    public function __construct()
    {
        //
    }

    public function index(Request $request, Response $response, $args)
    {
        $response->getBody()->write("Hello");
        return $response;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment