Skip to content

ch00_installation

Daniel Samson edited this page Mar 14, 2019 · 15 revisions

Get teensyphp

composer require daniel-samson/teensyphp

Create index.php

<?php
require_once __DIR__ . '/vendor/autoload.php';
display_errors(false);
error_reporting(E_ALL);

try {
    // home / landing page
    route(method(GET), url_path("/"), function () {
        render(200, json_out(['hello' => 'world']));
    });

    // route not found
    render(404, json_out(['hello' => 'world']));
} catch (Exception $e) {
    error_log($e->getMessage());
    error_log($e->getTraceAsString());
    render(500, html_out(['hello' => 'world']));
} catch (Error $e) {
    error_log($e->getMessage());
    error_log($e->getTraceAsString());
    render(500, html_out(template(__DIR__ . '/templates/error-50x.php', [])));
}
Clone this wiki locally