Last active
August 29, 2015 14:25
-
-
Save rossriley/c550ef1c6a36b4be8c17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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