Edit on GitHub
Jump to docs navigation

Extending / Storage Layer / Working with Queries

Note: You are currently reading the documentation for Bolt 3.7. Looking for the documentation for Bolt 5.2 instead?


In the new storage system it contains the query object that provides additional functionality to work with the database. You can access the query functionality by using the following service - $app['query']. The query allows access to the TWIG method setcontent. Internally $app['query'] is used to run this. An example of this functionality can be seen here -

Fetching Content

// getContent has two parameters - the query and the parameters
// Examples of usage:

// Get page with id 1
$page = $app['query']->getContent('pages', ['id' => 1]);

// Get about page and only return ONE
$page = $app['query']->getContent('pages/about', ['returnsingle' => true]);

// Get page with id 2
$pages = $app['query']->getContent('pages/2');

// Search pages
$pages = $app['query']->getContent('pages/search', ['filter' => 'term']);

// Get the latest pages
$pages = $app['query']->getContent('pages/latest');

// Get the latest five pages
$pages = $app['query']->getContent('pages/latest/5');

// Pagination is not yet implemented
// Get relationships
$page = $app['query']->getContent('pages/1');

foreach ($page->relation['entries'] as $item) {
    // Access relationship in here ... Item will be EntityProxy, but can be accessed like a Content object
    // OR ... $item->toArray(); will return all fields

// Checking if item has related items
$page = $app['query']->getContent('pages/1');


Edit this page on GitHub
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.