klsoft/yii3-datareader-doctrine 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

klsoft/yii3-datareader-doctrine

最新稳定版本:1.0.1

Composer 安装命令:

composer require klsoft/yii3-datareader-doctrine

包简介

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

README 文档

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 Klsoft\Yii3DataReaderDoctrine\Filter\ObjectEquals;
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 ObjectEquals('id', 1)
                        )
                    )
                    ->withOffset(0)
                    ->withLimit(20)
                    ->withSort(Sort::any()
                    ->withOrder(['id' => 'asc']))
            ]
        );
    }
}

Example of using the DoctrineDataReader with the GridView from the yiisoft/yii-dataview package

UserController.php:

use App\Data\Entities\User;
use Doctrine\ORM\EntityManagerInterface;
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']))
                    ->withSort(Sort::any(['id', 'name'])
                    ->withOrder(['name' => 'asc']))
            ]
        );
    }
}

list_template.php:

<?php

declare(strict_types=1);

use Yiisoft\View\WebView;
use Yiisoft\Yii\DataView\GridView\Column\DataColumn;
use Yiisoft\Yii\DataView\GridView\GridView;
use Yiisoft\Yii\DataView\YiiRouter\UrlParameterProvider;
use Yiisoft\Yii\DataView\YiiRouter\UrlCreator;
use Yiisoft\Router\CurrentRoute;
use Yiisoft\Router\UrlGeneratorInterface;
use Yiisoft\Data\Paginator\OffsetPaginator;
use Yiisoft\Data\Reader\DataReaderInterface;

/**
 * @var WebView $this
 * @var CurrentRoute $currentRoute
 * @var UrlGeneratorInterface $urlGenerator
 * @var DataReaderInterface $dataReader
 */

$this->setTitle('Users');
?>
<h1>Users</h1>
<?= GridView::widget()
    ->dataReader((new OffsetPaginator($dataReader))->withPageSize(20))
    ->urlParameterProvider(new UrlParameterProvider($currentRoute))
    ->urlCreator(new UrlCreator($urlGenerator))
    ->columns(
        new DataColumn(
            property: 'id',
            filter: true
        ),
        new DataColumn(
            property: 'name',
            filter: true
        ),
        new DataColumn(
            property: 'email',
            filter: true
        )
    )
?>

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固