예제 #1
0
    //setting up connection to our database
    $DB = new PDO($server, $username, $password);
    //Throw an exception when an error is encountered in the query
    $DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $DB->exec("SET NAMES 'utf8'");
} catch (Exception $e) {
    echo "Could not connect to the database";
    exit;
}
$app = new Silex\Application();
$app["debug"] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../../views'));
use Symfony\Component\HttpFoundation\Request;
Request::enableHttpMethodParameterOverride();
/**
 * Routing to twig templete views
 */
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig', array('sites' => Sites::getAll()));
});
$app->get('/site/{id}', function ($id) use($app) {
    $sites = Sites::getAll();
    function name($sites, $id)
    {
        $id = $id - 1;
        return $sites[$id];
    }
    $sites = name($sites, $id);
    return $app['twig']->render('site.html.twig', array('sites' => $sites, 'analytics' => ReturnedAnalytics::getAll($id)));
});
return $app;