PHP code example of ssv445 / aggregation-builder-pagination-bundle
1. Go to this page and download the library: Download ssv445/aggregation-builder-pagination-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ssv445 / aggregation-builder-pagination-bundle example snippets
// config/bundles.php
return [
// ...
Ludo\Bundle\AggregationBuilderPaginationBundle\LudoAggregationBuilderPaginationBundle::class => ['all' => true],
];
// src/Repository/ExampleRepository.php
use Doctrine\ODM\MongoDB\Aggregation\Builder as AggregationBuilder;
// ...
class ExampleRepository extends Repository
{
public function getExamples(): AggregationBuilder
{
$ab = $this->createAggregationBuilder();
$ab->hydrate(Example::class)
->match()
->field('field')
->equals('value');
return $ab;
}
}
// src/Subfolder/ExamplePagination.php
// ...
class ExamplePagination
{
// ...
public function __construct(DocumentManager $manager, PaginatorInterface $paginator)
{
$this->manager = $manager;
$this->paginator = $paginator;
}
public function getPaginatedExamples(): PaginationInterface
{
return $this->paginator->paginate(
$this->manager->getRepository(ExampleRepository::class)->getExamples()
);
}
}