Beispiel #1
0
<?php

// Default index page
router('GET', '^/$', function () {
    // Redirect request to controller
    $controller = new \App\Controller\IndexController();
    $controller->index();
});
// Page
router('GET', '^/company$', function () {
    echo "ACME";
});
// Sub page, available for GET and POST method
// /page/page2
router(['GET', 'POST'], '^/page/page2$', function () {
    echo "Yeah!";
});
// With named groups
// /hello/max/100
router('GET', '^/hello/(?<name>\\w+)/(?<id>\\d+)$', function ($params) {
    echo "Hello:";
    print_r($params);
});
header("HTTP/1.0 404 Not Found");
echo '404 Not Found';
Beispiel #2
0
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('host' => $db_config['DB_HOST'], 'dbname' => $db_config['DB_NAME'], 'password' => $db_config['DB_PASSWORD'], 'user' => $db_config['DB_USER'], 'charset' => $db_config['DB_CHARSET'])));
$app['file_service'] = function () {
    return new App\Service\FileService();
};
$app['getid3'] = function () {
    return new getID3();
};
$app['file_mapper'] = function () use($app) {
    $qb = $app['db']->createQueryBuilder();
    return new App\Mapper\FileMapper($qb);
};
//Index controller routing
$index_controller = $app['controllers_factory'];
$index_controller->get('/', function () use($app) {
    $controller = new App\Controller\IndexController($app);
    return $controller->index();
})->bind('main');
$index_controller->post('/', function (Request $request) use($app) {
    $controller = new App\Controller\IndexController($app);
    return $controller->upload($request);
});
$index_controller->get('/download/{file_id}', function ($file_id) use($app) {
    $controller = new App\Controller\IndexController($app);
    return $controller->download($file_id);
});
$index_controller->post('/save/{file_id}', function ($file_id, Request $request) use($app) {
    $controller = new App\Controller\IndexController($app);
    return $controller->save($file_id, $request);
});
$index_controller->get('/delete/{file_id}', function ($file_id) use($app) {
    $controller = new App\Controller\IndexController($app);