Hello folks, I struggle a lot with some pagination. So basically I do:
reconfing 'view' in app/view/config like so:
'pagination' => 'pagination.ZurbPresenter'
I have 'ZurbPresenter' file in app\views\pagination:
<?php class ZurbPresenter extends Illuminate\Pagination\Presenter { public function getActivePageWrapper($text) { return '<li class="current"><a href="">'.$text.'</a></li>'; } public function getDisabledTextWrapper($text) { return '<li class="unavailable">'.$text.'</li>'; } public function getPageLinkWrapper($url, $page) { return '<li><a href="'.$url.'">'.$page.'</a></li>'; } } ?>And finally the view:
<ul class="pagination">
<?php echo with(new ZurbPresenter($models))->render(); ?>
</ul>
I receive this error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR)
Class 'ZurbPresenter' not found
31.<ul class="pagination"> 32.<?php echo with(new ZurbPresenter($paginator))->render(); ?> 33.</ul>
I am stuck and confused what to do. Please help.
'pagination' => 'pagination.custom'
Create a file custom.php in views/pagination/ and copy this in (modify as needed):
<?php
$presenter = new Illuminate\Pagination\BootstrapPresenter($paginator);
?>
<?php if ($paginator->getLastPage() > 1): ?>
<div class="pagination">
<ul>
<?php echo $presenter->render(); ?>
</ul>
</div>
<?php endif; ?>
Save the ZurbPresenter.php in app/{your_project_name_or_something}/Presenters/ and paste code:
<?php
namespace {your_project_name_or_something}\Presenters;
class ZurbPresenter extends \Illuminate\Pagination\Presenter {
public function getActivePageWrapper($text)
{
return '<li class="current"><a href="">'.$text.'</a></li>';
}
public function getDisabledTextWrapper($text)
{
return '<li class="unavailable">'.$text.'</li>';
}
public function getPageLinkWrapper($url, $page, $rel = null)
{
return '<li><a href="'.$url.'">'.$page.'</a></li>';
}
}
I added the namespace (modify it) and $rel = null because it's throwing an error without it.
Modify composer.json:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
],
"psr-4": {
"{your_project_name_or_something}\\": "app/"
}
},
After that open command line and cd to project dir and run "composer dump-autoload -o"
{{ with(new {your_project_name_or_something}\Presenters\ZurbPresenter($models))->render() }}
I hope I haven't missed anything.
Great. Thanks man. This totally works. But one more thing - When it render the pagination it look like this ->
« 1 2 »
How can I remove the '« »' symbols?
To remove the unclickable one use "return null;" on getDisabledTextWrapper. I haven't figured out the ones that are links.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community