定制 thephpguys/spiral-datagrid-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

thephpguys/spiral-datagrid-bundle

Composer 安装命令:

composer require thephpguys/spiral-datagrid-bundle

包简介

README 文档

README

This bundle provides integration for spiral/data-grid with your Symfony project. Inspired by spiral/data-grid-bridge package, it offers the following features:

  • Seamless integration of the DataGrid component into a Symfony environment
  • Doctrine\ORM\QueryBuilder writer for constructing DQL based on filters.
  • DataGrid attribute for controllers

DataGrid Component Documentation

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

composer require thephpguys/spiral-datagrid-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

composer require thephpguys/spiral-datagrid-bundle

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    ThePhpGuys\SpiralDataGridBundle\SpiralDataGridBundle::class => ['all' => true],
];

Usage

Step 1: Create grid schema

Create a grid schema by defining filters, sorters, and pagination settings. You can find more filters on the DataGrid documentation page :

namespace App\Grid;
use App\Entity\Product;
use Spiral\DataGrid\GridSchema;
use Spiral\DataGrid\Specification\Filter;
use Spiral\DataGrid\Specification\Pagination\PagePaginator;
use Spiral\DataGrid\Specification\Sorter\Sorter;
use Spiral\DataGrid\Specification\Value\StringValue;

final class ProductGrid extends GridSchema
{

    public function __construct()
    {
        $this->addFilter('search',  new Filter\Any(
            new Filter\Like('e.title'),
            new Filter\Equals('e.article')
        ));
        $this->addSorter('name',new Sorter('e.name'));
        $this->addSorter('article',new Sorter('e.article'));
        $this->setPaginator(new PagePaginator(10, [10, 20, 50, 100]));
    }

    public function withDefaults():array
    {
        return [
            GridFactory::KEY_SORT => ['name'=>'asc']
        ];
    }

    //If this method exists it will be used as response data transformer
    public function __invoke(Product $product):array
    {
        return [
            'id' => $product->getId(),
            'name' => $product->getName(),
            'article' => $product->getArticle(),
        ];
    }
}

Step 2: Register schema as service

Register your grid schema as a service in config/services.yaml:

#config/services.yaml

services:
    App\Grid\ProductGrid:

Step 3: Create controller method

Create a controller method to use the DataGrid:

use App\Entity\Product;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Attribute\Route;
use ThePhpGuys\SpiralDataGridBundle\Attribute\DataGrid

//...
#[Route('/products')]
#[DataGrid(grid: ProductGrid::class)]
public function productsList(EntityManagerInterface $entityManager):QueryBuilder
{
    return $entityManager->createQueryBuilder()->select('*')->from('e',Product::class);
} 
//...

This setup provides a route with JSON response and query parameters for filters, sorters, and pagination.

Example Usage

thephpguys/spiral-datagrid-bundle 适用场景与选型建议

thephpguys/spiral-datagrid-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「datagrid」 「symfony-datagrid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 thephpguys/spiral-datagrid-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 thephpguys/spiral-datagrid-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 thephpguys/spiral-datagrid-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-25