示例#1
0
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Получение списка всех книг (twig)
$app->get('/library/book', function () use($getAllProperty) {
    $data = ['data' => $getAllProperty('', 'library', '', '')];
    return twig_render('book.twig', $data);
});
// Поиск книг с $name в названии (twig)
$app->get('/library/book/search/{name}', function ($name) use($getAllProperty) {
    $data = ['name' => $name, 'data' => $getAllProperty('', 'library', 'book_name', $name)];
    return twig_render('book.twig', $data);
})->assert('name', '\\w+');
// Поиск книг по id (twig)
$app->get('/library/book/{id}', function ($id) use($getAllProperty) {
    $data = ['name' => $id, 'data' => $getAllProperty('', 'library', 'id', $id)];
    return twig_render('book.twig', $data);
})->assert('id', '\\w+');
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Получение списка всех книг (REST)
$app->get('/api/library/book', function () use($getAllProperty) {
    $data = $getAllProperty('', 'library', '', '');
    return print_r($data, 1);
});
// Поиск книг с $name в названии (REST)
$app->get('/api/library/book/search/{name}', function ($name) use($getAllProperty) {
    $data = $getAllProperty('', 'library', 'book_name', $name);
    return print_r($data, 1);
})->assert('name', '\\w+');
// Получение книги по id (REST)
$app->get('/api/library/book/{id}', function ($id) use($getAllProperty) {
    $data = $getAllProperty('', 'library', 'id', $id);
示例#2
0
<?php

/**
 * Bloge application
 * 
 * @package bloge/meta-out-pack
 */
use Bloge\Apps\AdvancedApp;
use Bloge\Content\Advanced;
use Bloge\Content\Raw as Content;
use Bloge\Renderers\Twig as Renderer;
function twig_render($string, array $data)
{
    $twig = new Twig_Environment(new Twig_Loader_String());
    return $twig->render($string, $data);
}
$content = __DIR__ . '/content';
$theme = __DIR__ . '/theme';
$renderer = new Renderer($theme);
$content = new Advanced(new Content($content));
$content->processor()->add(Bloge\process('content', [new Parsedown(), 'text']))->add(function ($route, $data) {
    if ($route === 'blog') {
        $data['content'] = twig_render($data['content'], $data);
    }
    return $data;
});
$content->dataMapper()->mapAll(['view' => 'page.twig'])->map(spyc_load_file(__DIR__ . '/meta.yml'))->map('blog', ['title' => 'Bloggin is awesome!', 'posts' => $content->browse('blog')]);
return new AdvancedApp($content, $renderer);