Please how best can one do a pagination in a project using slim framework? i have googled around to see if there was a tutorial done on that but couldn’t find one. can i get help here?
Sorry i forgot to add i’m using eloquent db and twig template.
In this class, I fetch 16 items from the DB and post them… You provide a page number
class ShowGridAction extends Action
{
protected $perPage = 16;
public function render($event_string, $page = 0) {
$event = CampaignEvent::findByString($event_string);
if (! $event instanceof CampaignEvent) {
$this->app->render("cs/error/404.php", ["msg" => "Event Not Found"]);
$this->app->stop();
}
if ($this->app->request->isAjax()) {
$thumbs = EventMediaItem::getThumbnailsForOnPage($event->id, $page, $this->perPage);
$base = $this->app->view()->get('base');
//Todo put in template file
?><div class="row"><?php
foreach ($thumbs as $thumbnail) {
?>
<div class="col-xs-6 col-md-3">
<a href="<?= $base ?>/<?= $event_string ?>/<?= $thumbnail->image_filename ?>?p=<?= rand(0, 100000) ?>" target="_self">
<img src="<?= $base ?><?= $thumbnail->thumbnail_path ?>" class="img-responsive"/>
</a>
</div>
<?php
}
?></div><?php
} else {
$this->app->render('cx/image_grid.php', array(
"event_string" => $event_string,
"theme" => $event->getTheme(),
"page" => $page,
"max_page" => ceil(EventMediaItem::getThumbnailCountFor($event->id) / $this->perPage)
));
}
}
public function init()
{
// TODO: Implement init() method.
}
}
This is just some old code… maybe itll help you out.
Take a look at https://laravel.com/docs/5.1/pagination … pagination with eloquent is really easy.
Have you actually used it outside of Laravel ?
You get this error when you call links or render:
Type: Error
Message: Call to a member function make() on null
File: /home/vagrant/Code/slim/** Your Project**/vendor/illuminate/pagination/LengthAwarePaginator.php
Line: 90
It’s expecting static::viewFactory()->make which does not exist, at least outside of Laravel.