spyrit / propel-datagrid-bundle
Symfony2 Datagrid Bundle for Propel.
Installs: 36 570
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 10
Forks: 3
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.0.0
- csanquer/colibri-csv: ~1.2
- propel/propel: ^2.0@alpha|2.0.x-dev
- symfony/monolog-bundle: ~2.4|~3.0
- symfony/symfony: ~3.4|~4.0|~5.0
Requires (Dev)
- phpunit/phpunit: ~6.0|~7.0
- propel/propel-bundle: 4.0.x-dev
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-csv
1.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 (maintained) is for Propel2 and Symfony4
- Branch 5.0 (maintained) is for Propel2 and Symfony5
Enable the bundle
You won't be surprised to be asked to add the following line in your Kernel :
// app/AppKernel.php <?php // ... public function registerBundles() { $bundles = array( // ... // don't forget the PropelBundle too new Spyrit\PropelDatagridBundle\SpyritPropelDatagridBundle(), ); }
Try the demo
A demo is included in the demo branch which is updated with the master updates. To try it, follow these few steps :
- Build your model
app/console propel:build
- Create the database structure
app/console propel:sql:insert
- Publish assets in your web directory (in symlink mode?)
app/console assets:install --symlink
- Add a route to the PropelDatagridBundle routing file :
spyrit_propel_datagrid: resource: "@SpyritPropelDatagridBundle/Resources/config/routing.yml"
If you used this previous code sample and didn't add a prefix to the route, you should access to the demo with this URL : ://<your_dommain>/datagrid/demo/book/list
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() { } public function getDefaultSortColumn() { } public function getName() { } }
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
Todo
Display your datagrid - The view's Job and yours (or designer)
Todo
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.