Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/makscraft/pagination
Pagination manager for Symfony application.
https://github.com/makscraft/pagination
php symfony twig
Last synced: about 1 month ago
JSON representation
Pagination manager for Symfony application.
- Host: GitHub
- URL: https://github.com/makscraft/pagination
- Owner: makscraft
- License: mit
- Created: 2024-07-26T10:47:51.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-07-30T14:41:07.000Z (4 months ago)
- Last Synced: 2024-09-30T17:21:21.726Z (about 2 months ago)
- Topics: php, symfony, twig
- Language: PHP
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pagination
Pagination manager for Symfony applications.Generates list of links and parameters for SQL queries.
![pagination](https://github.com/user-attachments/assets/620c1f38-3b7d-4764-b186-38c5e2031e7c)
Installation
---
```
composer require makscraft/pagination
```Example of use in controller or repository
---```
use Makscraft\Pagination;$total = ... ; //count your all needed items
$limit = 20; //items per page$pagination = new Pagination($total, $limit);
$repository -> findBy([...], [...], $pagination -> getLimit(), $pagination -> getOffset());
//Returns array of links for html template.
$data = $pagination -> setPath('/catalog') -> getDisplayData();
```
Result links in $data will look like: '/catalog?page=3'.You can pass the path with additional GET parameters if you want.
```
$pagination -> setPath('/catalog?sort=name&direction=asc');
```For twig templates
---Use package twig template or copy it into templates directory of your project.
Inside the controller pass the pagination object into template.
```
return $this -> render('mypage.html.twig', [
...
'pagination' => $pagination
]);
```
To use template from vendor directory add the path into twig config file.
```
# config/packages/twig.yaml
paths:
'vendor/makscraft/pagination/templates': 'pagination'```
Next include the pagination template into your twig files.
```
{% include '@pagination/pagination.html.twig' %}
```Also you can copy the template file into your templates directory and use it as you like.
Template file location: **vendor/makscraft/pagination/templates/pagination.html.twig**