PHP code example of lucasgiori / doctrine-pagination
1. Go to this page and download the library: Download lucasgiori/doctrine-pagination 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/ */
lucasgiori / doctrine-pagination example snippets
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Task
*
* @ORM\Table(name="task")
* @ORM\Entity(repositoryClass="DoctrinePagination\ORM\PaginatedRepository")
*/
class Task
{
}
namespace Repository;
use DoctrinePagination\ORM\PaginatedQueryBuilder;
use DoctrinePagination\ORM\PaginatedRepository;
/**
* Class TaskRepository
*/
class TaskRepository extends PaginatedRepository
{
}
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Task
*
* @ORM\Table(name="task")
* @ORM\Entity(repositoryClass="Repository\TaskRepository")
*/
class Task
{
}
protected function processCriteria(PaginatedQueryBuilder $qb, array $criteria)
{
foreach ($criteria as $field => $value) {
switch ($field) {
case 'description':
$qb->andWhere(...);
unset($criteria[$field]);
break;
}
}
parent::processCriteria($qb, $criteria);
}
use Doctrine\ORM\Query;
use DoctrinePagination\DTO\Params;
$params = (new Params())
->setCriteria(["field" => "teste"]) // Array the fields and values to apply filter in sql
->setPage(1) // Page of query data
->setPerPage(10) // Quantity per page
->setHydrateMode(Query::HYDRATE_ARRAY) //Result handling mode
->setSearchField("nome") // Search Field define field to apply `like` of sql
->setSearch("gazin"); // Field Value apply `like` in sql
use DoctrinePagination\ORM\PaginatedRepository;
use DoctrinePagination\DTO\Params;
class Example extends PaginatedRepository {
public function findWithFilter(Params $params): ?PaginatedArrayCollection
{
return $this->findPageWithDTO($params);
}
}