Esempio n. 1
0
 public function testAllPredicates()
 {
     // startgist:7a6da96d9e6f94269057:prismic-allPredicates.php
     // "at" predicate: equality of a fragment to a value.
     $at = Predicates::at("document.type", "article");
     // "any" predicate: equality of a fragment to a value.
     $any = Predicates::any("document.type", array("article", "blog-post"));
     // "fulltext" predicate: fulltext search in a fragment.
     $fulltext = Predicates::fulltext("my.article.body", "sausage");
     // "similar" predicate, with a document id as reference
     $similar = Predicates::similar("UXasdFwe42D", 10);
     // endgist
 }
});
// Author
$app->get('/author/:id/:slug', function ($id, $slug) use($app, $prismic) {
    $author = $prismic->get_document($id);
    if (!$author) {
        not_found($app);
        return;
    }
    $posts = $prismic->form()->query(Predicates::at('document.type', 'post'), Predicates::at('my.post.author', $id))->fetchLinks('post.date', 'category.name', 'author.full_name', 'author.first_name', 'author.surname', 'author.company')->orderings('my.post.date desc')->page(current_page($app))->submit();
    $skin = $prismic->get_skin();
    render($app, 'author', array('posts' => $posts, 'author' => $author, 'skin' => $skin));
});
// Search results
$app->get('/search', function () use($app, $prismic) {
    $q = $app->request()->params('q');
    $posts = $prismic->form()->query(Predicates::at('document.type', 'post'), Predicates::fulltext('document', $q))->fetchLinks('post.date', 'category.name', 'author.full_name', 'author.first_name', 'author.surname', 'author.company')->orderings('my.post.date desc')->page(current_page($app))->submit();
    $skin = $prismic->get_skin();
    render($app, 'search', array('posts' => $posts, 'skin' => $skin));
});
// Category
$app->get('/category/:uid', function ($uid) use($app, $prismic) {
    $cat = $prismic->by_uid('category', $uid);
    if (!$cat) {
        not_found($app);
        return;
    }
    $posts = $prismic->form()->query(Predicates::at('document.type', 'post'), Predicates::any('my.post.categories.link', array($cat->getId())))->fetchLinks('post.date', 'category.name', 'author.full_name', 'author.first_name', 'author.surname', 'author.company')->orderings('my.post.date desc')->page(current_page($app))->submit();
    $skin = $prismic->get_skin();
    render($app, 'category', array('category' => $cat, 'posts' => $posts, 'skin' => $skin));
});
// Tag