spyrit/propel-datagrid-bundle
Composer 安装命令:
composer require spyrit/propel-datagrid-bundle
包简介
Symfony2 Datagrid Bundle for Propel.
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
Since composer is the simplest and fastest way to install dependencies, the only way to install this bundle automatically is to add the following line to your dependencies
composer require spyrit/propel-datagrid-bundle
- Branches 1.x (unmaintained) are for Propel1 and Symfony2
- Branch 1.0 is for backward-compatibility with old projects (PHP < 5.4).
- Branch 1.1 requires PHP-5.4+ for
csanquer/colibri-csv 1.2 - Branch 1.2 integrates new functionnalities like dynamic max-per-page value
- Branch 1.3 implements batch (mass) actions
- Branches 2.x (unmaintained) are for Propel2 and Symfony2
- Branch 2.0 is for backward-compatibility with old projects (PHP < 5.4).
- Branch 2.1 requires PHP-5.4+ for
csanquer/colibri-csv1.2 - Branch 2.2 integrates new functionnalities like dynamic max-per-page value
- Branch 2.3 implements batch (mass) actions
- Branch 3.0 (unmaintained) is for Propel2 and Symfony3
- Branch 4.0 (unmaintained) is for Propel2 and Symfony4
- Branch 5.0 (maintained) is for Propel2 and Symfony5
- Branch 6.0 (maintained) is for Propel2 and Symfony6
- requires PHP-7.4+
- requires
spyrit/colibri-csv1.3 - recommends the usage of PropelBundle fork in your composer.json https://github.com/SkyFoxvn/PropelBundle
- BC: DataGrid no longer depends of
Symfony\Component\DependencyInjection\ContainerInterface. It depends ofSymfony\Component\HttpFoundation\RequestStackSymfony\Component\Form\FormFactoryInterfaceSymfony\Component\Routing\RouterInterface
- BC: Use service autowiring, see https://github.com/spyrit/PropelDatagridBundle?tab=readme-ov-file#declare-your-datagrid---the-controllers-job
Enable the bundle
Enable the bundle in your application
// config/bundles.php <?php return [ ... Spyrit\PropelDatagridBundle\SpyritPropelDatagridBundle::class => ['all' => true],
Usage
May be the most interesting part of this documentation which quickly describe how to create and use your first Datagrid.
Create your datagrid - Your Job
To create a datagrid you have to create a single class that inherit from the PropelDatagrid object and implement all methods from the PropelDatagridInterface :
<?php namespace Spyrit\PropelDatagridBundle\Datagrid\Demo; use Spyrit\PropelDatagridBundle\Datagrid\PropelDatagrid; class BookDatagrid extends PropelDatagrid { public function configureQuery() { return BookQuery::create(); } public function getDefaultSortColumn() { return 'id'; } public function getName() { return 'book'; } public function configureFilter() { return [ 'id' => [ 'type' => IntegerType::class, 'options' => [ 'label' => '#', 'required' => false, ], ], 'title' => [ 'type' => TextType::class, 'options' => [ 'label' => 'Title', ], ] ]; } }
The configureQuery method must return a predefined PropelQuery object (example: BookQuery object) as shown here :
<?php //... public function configureQuery() { return BookQuery::create() ->joinWith('Author', \Criteria::LEFT_JOIN) ->joinWith('Publisher', \Criteria::LEFT_JOIN) ; }
Declare your datagrid - The Controller's Job
<?php
namespace App\Controller;
use App\Propel\Annonce;
use App\Propel\AnnonceQuery;
use App\Datagrid\BookDatagrid;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/books')]
class BookController extends AbstractController
{
#[Route('/')]
public function list(BookDatagrid $annonceDatagrid): Response
{
$datagrid = $annonceDatagrid->execute();
return $this->render('book/list.html.twig', [
'datagrid' => $datagrid,
]);
}
}
Display your datagrid - The view's Job and yours (or designer)
{% extends "base.html.twig" %}
{% import "@SpyritPropelDatagrid/Datagrid/macros.html.twig" as macros %}
{% block body %}
{% set form = datagrid.filterFormView %}
<form method="post">
{{ form_widget(form.id) }}
{{ form_widget(form.title) }}
{{ form_errors(form) }}
{{ form_rest(form) }}
</form>
<table>
<thead>
<tr>
<th>{{ macros.sort('id', "#", route, datagrid) }}</th>
<th>{{ macros.sort('title', "Title", route, datagrid) }}</th>
</tr>
</thead>
<tbody>
{% for book in datagrid.results %}
<tr>
<td>{{ book.id }}</td>
<td>{{ book.title }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
Export datagrid data
Todo
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/propel-datagrid-bundle 适用场景与选型建议
spyrit/propel-datagrid-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45.81k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2014 年 08 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「propel」 「datagrid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spyrit/propel-datagrid-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spyrit/propel-datagrid-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spyrit/propel-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.
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 45.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-08-29