コード例 #1
0
ファイル: routes.php プロジェクト: odan/dandy
<?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';
コード例 #2
0
$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);
    return $controller->delete($file_id);
});
$index_controller->get('/lastfiles', function () use($app) {
    $controller = new App\Controller\IndexController($app);
    return $controller->lastFiles();
})->bind('lastfiles');
$index_controller->get('/{file_id}', function ($file_id) use($app) {
    $controller = new App\Controller\IndexController($app);
    return $controller->fileDetail($file_id);
});
$app->mount('/', $index_controller);
$app->run();