Пример #1
0
// pass the configuration on app init //////////////////////////////////////////
// $app = new \Slim\App($c);
$app = new \Slim\App();
// define the $app's package dependencies inside containers ////////////////////
$container = $app->getContainer();
// Twig is to render basic html, it has other uses but we have no choice to use
// a rendering engine with Slim ////////////////////////////////////////////////
$container['view'] = function ($container) {
    $view = new \Slim\Views\Twig($_SERVER['DOCUMENT_ROOT'] . '/src/client/', ['cache' => false]);
    $view->addExtension(new \Slim\Views\TwigExtension($container['router'], $container['request']->getUri()));
    return $view;
};
// duncan3dc\SqlClass\Sql is a data/abstraction layer class for interfacing ////
// with our db: why reinvent the wheel? ////////////////////////////////////////
$container['sql'] = function ($container) {
    duncan3dc\SqlClass\Sql::addServer('le-huard', ['mode' => getenv('MODE'), 'hostname' => getenv('HOSTNAME'), 'username' => getenv('USERNAME'), 'password' => getenv('PASSWORD'), 'database' => getenv('DB')]);
    $sql = duncan3dc\SqlClass\Sql::getInstance('le-huard');
    return $sql;
};
/////////////// end app config and container declaration //////////////////////
/////////////////////////////////// ROUTES /////////////////////////////////////
// when accessing the root of the website we should return the angul app at ////
// index.html and let it handle its own routes /////////////////////////////////
$app->get('/', function ($request, $response, $args) {
    // serve the angular app ///////////////////////////////////////////////////
    return $this->view->render($response, '/app/index.html');
});
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// API ///////////////////////////////////////////
// API routes should either return json data based on the Database or a header
// status code
Пример #2
0
$c = new \Slim\Container($configuration);
// pass the configuration on app init //////////////////////////////////////////
$app = new \Slim\App($c);
// define the $app's package dependencies inside containers ////////////////////
$container = $app->getContainer();
// Twig is to render basic html, it has other uses but we have no choice to use
// a rendering engine with Slim ////////////////////////////////////////////////
$container['view'] = function ($container) {
    $view = new \Slim\Views\Twig($_SERVER['DOCUMENT_ROOT'] . '/src/client/', ['cache' => false]);
    $view->addExtension(new \Slim\Views\TwigExtension($container['router'], $container['request']->getUri()));
    return $view;
};
// duncan3dc\SqlClass\Sql is a data/abstraction layer class for interfacing ////
// with our db: why reinvent the wheel? ////////////////////////////////////////
$container['sql'] = function ($container) {
    duncan3dc\SqlClass\Sql::addServer('le-huard', ['mode' => 'mysql', 'hostname' => '127.0.0.1', 'username' => 'root', 'password' => 'admin', 'database' => 'le-huard']);
    $sql = duncan3dc\SqlClass\Sql::getInstance('le-huard');
    return $sql;
};
/////////////// end app config and container declaration //////////////////////
/////////////////////////////////// ROUTES /////////////////////////////////////
// when accessing the root of the website we should return the angul app at ////
// index.html and let it handle its own routes /////////////////////////////////
$app->get('/', function ($request, $response, $args) {
    // serve the angular app ///////////////////////////////////////////////////
    return $this->view->render($response, '/app/index.html');
});
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// API ///////////////////////////////////////////
// API routes should either return json data based on the Database or a header
// status code