spyrit/doctrine-datagrid-bundle
Composer 安装命令:
composer require spyrit/doctrine-datagrid-bundle
包简介
Symfony Datagrid Bundle for Doctrine.
README 文档
README
This bundle helps you to create and manage simple to complex datagrids quickly and easily.
Unlike other similar bundle already available on Github and/or Packagist, there is no magic method that will render the datagrid in you view. This technical choice allow you to completely customize your datagrid aspect and render (filter fields, buttons, columns, data displayed in each column, pagination links and informations, etc.).
This make it easy to implement and use in both back-end and front-end applications.
Still skeptical? Let's see how it works!
Installation
Get the code
To install this bundle automatically, use Composer:
composer req spyrit/doctrine-datagrid-bundle
Use it
Create your datagrids:
<?php
namespace App\Datagrid;
use App\Entity\Video;
use Spyrit\Bundle\DoctrineDatagridBundle\Datagrid\DoctrineDatagrid;
use Spyrit\Bundle\DoctrineDatagridBundle\Datagrid\DoctrineDatagridFactory;
use Symfony\Component\Form\Extension\Core\Type\TextType;
class VideoDatagrid
{
private DoctrineDatagrid $datagrid;
public function __construct(DoctrineDatagridFactory $factory)
{
$this->datagrid = $factory
->create('video', ['multi_sort' => false])
->select(['video'])
->id('video.id')
->query(function ($qb) {
return $qb->from(Video::class, 'video');
})
->filter('title', TextType::class, [
'attr' => [
'placeholder' => 'Title',
],
'translation_domain' => false,
'required' => false,
], function ($value, $qb) {
return $qb->andWhere('video.title LIKE :title')
->setParameter('title', '%'.$value.'%');
})
->setDefaultSort(['video.id' => 'desc'])
->setDefaultMaxPerPage(30);
}
public function execute(): DoctrineDatagrid
{
return $this->datagrid->execute();
}
}
Use your datagrids in your controllers:
<?php
namespace App\Controller\Admin;
use App\Datagrid\VideoDatagrid;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/video")
*/
class VideoController extends Controller
{
/**
* @Route("/list", name="video_index", methods={"GET","POST"})
*/
public function index(VideoDatagrid $datagrid): Response
{
return $this->render('video/index.html.twig', [
'datagrid' => $datagrid->execute(),
]);
}
}
Render them in your views:
{% extends 'layout.html.twig' %}
{% import '@DoctrineDatagrid/Datagrid/macros.html.twig' as macros %}
{% set form = datagrid.filterFormView %}
{% set route = app.request.attributes.get('_route') %}
{% block body %}
<table class="table">
<thead>
<tr id="filters">
{{ form_start(form) }}
<td>
{{ form_widget(form.title) }}
</td>
<td class="text-right">
<button class="btn btn-primary">{{ 'Filter' }}</button>
<a href="{{ datagrid.resetPath(route) }}" class="btn btn-secondary">{{ 'Reset' }}</a>
</td>
{{ form_end(form) }}
</tr>
<tr>
<th>{{ 'Title' }}</th>
<th>{{ 'Description' }}</th>
</tr>
</thead>
<tbody>
{% for video in datagrid.results %}
<tr>
<td>{{ video.title }}</td>
<td>{{ video.description }}</td>
</tr>
{% else %}
<tr>
<td colspan="2">{{ 'No video' }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
{% include '@DoctrineDatagrid/Datagrid/pagination_info.html.twig' %}
</div>
<div class="col-md-4">
{% include '@DoctrineDatagrid/Datagrid/pagination.html.twig' %}
</div>
</div>
{% endblock %}
Credit
Our special thanks go to ...
- Charles SANQUER for its fork of the LightCSV library : Colibri CSV used in the export feature.
- Subosito for its standalone Inflector class transformed in a service for our needs.
spyrit/doctrine-datagrid-bundle 适用场景与选型建议
spyrit/doctrine-datagrid-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22.54k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「datagrid」 「doctrine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spyrit/doctrine-datagrid-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spyrit/doctrine-datagrid-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spyrit/doctrine-datagrid-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
FSi DataIndexer Component - Component created to provide one simple object indexing strategy for FSi DataSource and DataGrid components.
FSi DataGrid Component
The bundle for easy using json-rpc api on your project
Symfony DataGridBundle
A laravel package for using datagrids.
Make pimcore migration simple
统计信息
- 总下载量: 22.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-30