Beispiel #1
0
<?php

// список
$app->get('/lots', function () use($app) {
    $lots = Lot::fetch_all(null, null, false);
    $app->render('admin/lots.twig', array('lots' => $lots));
})->name('lots');
// форма редактирования
$app->get('/lots/:id', function ($id) use($app) {
    $lot = Lot::fetch($id);
    $app->render('admin/lot.twig', array('lot' => $lot, 'upload_dir' => $app->config('upload.path')));
})->name('lot');
// форма нового лота
$app->get('/new_lot', function () use($app) {
    $app->render('admin/lot.twig', array('new' => true));
})->name('new_lot');
// POST нового лота
$app->post('/lot_post', function () use($app) {
    $data = $app->request->post();
    if (!isset($data['status'])) {
        $data['status'] = UNPUBLISHED;
    }
    if (!isset($data['rent'])) {
        $data['rent'] = 0;
    }
    unset($data['preview']);
    try {
        if ($data['title'] == '') {
            throw new ErrorException('Поле "название" обязательно!');
        }
        $new_lot = Lot::post($data);
Beispiel #2
0
<?php

// счетчик кол-ва лотов
$app->get('/lot_count', function () use($app) {
    $data = array('total' => Lot::count(), 'published' => Lot::count(true));
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->setBody(json_encode($data));
});
// JSON всех лотов постранично
$app->get('/lot_pages(/:page)', function ($page = 1) use($app) {
    $limit = $app->config('lots_per_page');
    $offset = ($page - 1) * $limit;
    $lots = Lot::fetch_all($limit, $offset);
    $brief_data = array();
    foreach ($lots as $lot) {
        $brief_data[] = $lot->brief();
    }
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->setBody(json_encode($brief_data));
});
// полный JSON лота
$app->get('/lots/:id', function ($id) use($app) {
    $lot = Lot::fetch($id);
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->setBody(json_encode($lot));
});
// HTML видео
$app->get('/lots/:id/video', function ($id) use($app) {
    $app->render('video.twig', array('id' => $id));
});