klsoft/yii3-datareader-doctrine

The package provides a Yii 3 data reader that uses the Doctrine ORM

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/klsoft/yii3-datareader-doctrine

1.0.0 2026-02-26 15:20 UTC

This package is auto-updated.

Last update: 2026-02-26 15:22:30 UTC


README

The package provides a Yii 3 data reader that uses the Doctrine ORM.

Requirement

  • PHP 8.2 or higher.

Installation

composer require yii3-datareader-doctrine

How to use

Example:

use App\Data\Entities\User;
use Doctrine\ORM\EntityManagerInterface;
use Yiisoft\Data\Reader\Filter\AndX;
use Yiisoft\Data\Reader\Filter\Equals;
use Yiisoft\Data\Reader\Sort;
use Klsoft\Yii3DataReaderDoctrine\DoctrineDataReader;
use Yiisoft\Yii\View\Renderer\WebViewRenderer;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

final readonly class UserController
{
    public function __construct(
        private EntityManagerInterface $entityManager,
        private WebViewRenderer        $viewRenderer)
    {
    }

    public function list(ServerRequestInterface $request): ResponseInterface
    {
        return $this->viewRenderer->render(
            __DIR__ . '/list_template',
            [
                'dataReader' => (new DoctrineDataReader(
                    $this->entityManager,
                    User::class,
                    ['id', 'name', 'email']))
                    ->withFilter(new AndX(
                            new Equals('id', 1)
                        )
                    )
                    ->withOffset(0)
                    ->withLimit(20)
                    ->withSort(Sort::any()->withOrder(['id' => 'asc']))
            ]
        );
    }
}