コード例 #1
0
ファイル: app.php プロジェクト: alidzapp/MicroFramework-PHP
// Matches if the HTTP method is GET -> /login
$app->get('/login', function () use($app) {
    return $app->render('login.php');
});
// Matches if the HTTP method is GET -> /register
$app->get('/register', function () use($app) {
    return $app->render('register.php');
});
// Matches if the HTTP method is GET -> /logout
$app->get('/logout', function () use($app) {
    session_destroy();
    $app->redirect('/statuses');
});
// Matches if the HTTP method is GET -> /statuses
$app->get('/statuses', function (Request $request) use($app, $statusFinder) {
    $data = array('status' => $statusFinder->findAll());
    if ($request->guessBestFormat() === 'json') {
        return new JsonResponse($data);
    }
    if (isset($_SESSION['userName'])) {
        array_push($data, 'userName', $_SESSION['userName']);
    } else {
        array_push($data, 'userName', "NoUser");
    }
    return $app->render('index.php', $data);
});
// Matches if the HTTP method is GET -> /statuses/id
$app->get('/statuses/(\\d+)', function (Request $request, $id) use($app, $statusFinder) {
    if (null === ($status = $statusFinder->findOneById($id))) {
        throw new HttpException(404);
    }
コード例 #2
0
ファイル: app.php プロジェクト: PierreCharles/uFramework-PHP
// Matches if the HTTP method is GET -> /logout
$app->get('/logout', function () use($app) {
    session_destroy();
    $app->redirect('/statuses');
});
// Matches if the HTTP method is GET -> /statuses
$app->get('/statuses', function (Request $request) use($app, $statusFinder) {
    if (isset($_SESSION['error']) && !empty($_SESSION['error'])) {
        $data['error'] = $_SESSION['error'];
        $_SESSION['error'] = "";
    }
    $filter['order'] = $request->getParameter("order") ? htmlspecialchars($request->getParameter("order")) : "";
    $filter['by'] = $request->getParameter("by") ? htmlspecialchars($request->getParameter("by")) : "";
    $filter['limit'] = $request->getParameter("limit") ? htmlspecialchars($request->getParameter("limit")) : "";
    $filter['user_id'] = $request->getParameter("user_id") ? htmlspecialchars($request->getParameter("user_id")) : "";
    if (null === ($data['status'] = $statusFinder->findAll($filter))) {
        $data['status'] = "";
    }
    if ($request->guessBestFormat() === 'json') {
        return new JsonResponse(json_encode($data['status']), 200);
    }
    if (isset($_SESSION['user'])) {
        $data['user'] = $_SESSION['user'];
    } else {
        $data['user'] = '******';
    }
    return $app->render('index.php', $data);
});
// Matches if the HTTP method is GET -> /statuses/id
$app->get('/statuses/(\\d+)', function (Request $request, $id) use($app, $statusFinder) {
    if (!Validation::isInt($id)) {