[SonataAdminExtraExportBundle][sonata-admin-extra-export-bundle] is a PHP (5.4+) extension for Sonata Admin. By default Sonata Admin has json, xml, csv and xls export formats., (*1)
The SonataAdminExtraExportBundle provides a simple integration for your Symfony project with Sonata Admin and adds support of:, (*2)
Installation
With composer, add:, (*3)
{
"require": {
"whyte624/sonata-admin-extra-export-bundle": "dev-master"
}
}
Then enable it in your kernel:, (*4)
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new Whyte624\SonataAdminExtraExportBundle\Whyte624SonataAdminExtraExportBundle(),
new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
//...
Configuration
Configure KnpSnappyBundle., (*5)
[SonataAdminExtraExportBundle][sonata-admin-extra-export-bundle] requires you to add traits with export formats to Admin class and extension of export method to CRUDController class., (*6)
Add trait to Admin class:, (*7)
//src/Acme/AcmeBundle/Admin/MyAdmin.php
use Sonata\AdminBundle\Admin\Admin;
use Whyte624\SonataAdminExtraExportBundle\Admin\AdminExtraExportTrait;
class MyAdmin extends Admin
{
//...
use AdminExtraExportTrait;
//...
Add trait to CRUDController class, (*8)
//src/Acme/AcmeBundle/Controller/MyCRUDController.php
use Sonata\AdminBundle\Controller\CRUDController;
use Whyte624\SonataAdminExtraExportBundle\Controller\CRUDControllerExtraExportTrait;
class MyCRUDController extends CRUDController
{
//...
use CRUDControllerExtraExportTrait;
//...
This will add extra export formats to your admin., (*9)
Pdf layout
You can easily add your companies logo to PDF export, by overriding Whyte624SonataAdminExtraExportBundle::html_layout.html.twig. Just make sure, that paths for images and css that you are using are absolute., (*10)
Override getPdfOptions class in your CRUDController class to change orientation to landscape., (*11)