示例#1
0
<?php

require '../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => 'php://stderr'));
// Register view rendering
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
// Our web handlers
$app->get('/', function () use($app) {
    $app['monolog']->addDebug('logging output.');
    return $app['twig']->render('index.twig');
});
$app->get('/cowsay', function () use($app) {
    $app['monolog']->addDebug('cowsay');
    return "<pre>" . \League\Cowsayphp\Cow::say("Cool beans") . "</pre>";
});
$app->run();
示例#2
0
require '../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => 'php://stderr'));
// Register view rendering
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
// Our web handlers
//$app->get('/', function() use($app) {
//  $app['monolog']->addDebug('logging output.');
//  return $app['twig']->render('index.twig');
//});
$app->get('/cowsay', function () use($app) {
    $app['monolog']->addDebug('cowsay');
    return "<pre>" . \League\Cowsayphp\Cow::say("Aurelio Arias test") . "</pre>";
});
$app->get('/', function () use($app) {
    $app['monolog']->addDebug('logging output.');
    return str_repeat('Hello', getenv('TIMES'));
});
$dbopts = parse_url(getenv('DATABASE_URL'));
$app->register(new Herrera\Pdo\PdoServiceProvider(), array('pdo.dsn' => 'pgsql:dbname=' . ltrim($dbopts["path"], '/') . ';host=' . $dbopts["host"], 'pdo.port' => $dbopts["port"], 'pdo.username' => $dbopts["user"], 'pdo.password' => $dbopts["pass"]));
$app->get('/db/', function () use($app) {
    $st = $app['pdo']->prepare('SELECT name FROM test_table');
    $st->execute();
    $names = array();
    while ($row = $st->fetch(PDO::FETCH_ASSOC)) {
        $app['monolog']->addDebug('Row ' . $row['name']);
        $names[] = $row;
    }