Skip to content

Instantly share code, notes, and snippets.

@rossriley
Last active August 29, 2015 14:25
Show Gist options
  • Save rossriley/c550ef1c6a36b4be8c17 to your computer and use it in GitHub Desktop.
Save rossriley/c550ef1c6a36b4be8c17 to your computer and use it in GitHub Desktop.
1: Make this class
<?php
namespace Mysite\Bolt;
use Bolt\Application;
use Bolt\BaseExtension;
class GetEventsExtension extends BaseExtension
{
public function initialize()
{
$this->addTwigFunction('getEvents', 'getEvents');
}
protected function getEvents()
{
$tablename = <YOUR EVENT TABLE>;
// Get the current values from the DB.
$query = sprintf(
"SELECT xxxxx FROM %s WHERE xxxx AND xxx",
$tablename
);
$results = $this->app['db']->executeQuery(
$query,
..... all params here....
)->fetchAll();
$offset = ($app['request']->get('page', 1) -1) * 10;
$pager = array(
'for' => 'my_events',
'count' => count($results),
'totalpages' => ceil(count($results) / 10),
'current' => $app['request']->get('page', 1),
'showing_from' => $offset +1,
'showing_to' => $offset +10
);
$this->app['storage']->setPager('my_events', $pager);
return array_slice($results, $offset, 10);
}
public function getName()
{
return 'getEventsExtension';
}
}
//// End of file
2. Add this to your bootstrap
$app['extensions']->register(new \Mysite\Bolt\GetEventsExtension($app));
3. Call in your template.
{% set events = getEvents() %
{% for event in events %
........
{% endfor %
{{pager('my_events')}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment