doctrs / sonata-import-bundle
Import bundle to the Sonata Admin Bundle
Installs: 4 543
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 4
Forks: 11
Open Issues: 3
Type:symfony-bundle
Requires
- php: >=5.6
- sonata-project/admin-bundle: >=3.0
- white-october/pagerfanta-bundle: >=1.0
This package is not auto-updated.
Last update: 2025-03-30 05:23:03 UTC
README
Add import to sonata admin bundle
Installation
Run
composer require doctrs/sonata-import-bundle
Register the bundle in your AppKernel.php
new Doctrs\SonataImportBundle\DoctrsSonataImportBundle()
If you have not bundle white-october/pagerfanta-bundle
register this in AppKernel.php
too.
new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
Add orm mapping in your config.yml
doctrine: # ... orm: # ... entity_managers: default: mappings: DoctrsSonataImportBundle: ~
Add settings of bundle
doctrs_sonata_import: mappings: # - { name: center_point, class: doctrs.form_format.point} # - { name: city_autocomplete, class: doctrs.form_format.city_pa} - { name: date, class: doctrs.type.datetime} - { name: datetime, class: doctrs.type.datetime} - { name: boolean, class: doctrs.type.boolean} - { name: integer, class: doctrs.type.integer} - { name: entity, class: doctrs.type.entity} - { name: choice, class: doctrs.type.entity} upload_dir: %kernel.root_dir%/../web/uploads class_loaders: - { name: CSV, class: Doctrs\SonataImportBundle\Loaders\CsvFileLoader} # - { name: XLS, class: AppBundle\Loader\Doctrs\XlsFileLoader} encode: default: utf8 list: - cp1251 - utf8 - koir8
Update your database
php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate
If you have not migrations run this
php app/console doctrine:schema:update --force
Installation of bundle success
Change sonataAdminBundle entities
Add or change methods configureRoutes
and getDashboardActions
in sonata admin classes
use Sonata\AdminBundle\Admin\AbstractAdmin; ... class AnyClassAdmin extends AbstractAdmin { ... protected function configureRoutes(RouteCollection $collection) { $collection->add('import', 'import', [ '_controller' => 'DoctrsSonataImportBundle:Default:index' ]); $collection->add('upload', '{id}/upload', [ '_controller' => 'DoctrsSonataImportBundle:Default:upload' ]); $collection->add('importStatus', '{id}/upload/status', [ '_controller' => 'DoctrsSonataImportBundle:Default:importStatus' ]); } ... public function getDashboardActions() { $actions = parent::getDashboardActions(); $actions['import'] = array( 'label' => 'Import', 'url' => $this->generateUrl('import'), 'icon' => 'upload', 'template' => 'SonataAdminBundle:CRUD:dashboard__action.html.twig', // optional ); return $actions; }
If you don't redefined these methods you can use trait
use Doctrs\SonataImportBundle\Admin\AdminImportTrait; use Sonata\AdminBundle\Admin\AbstractAdmin; ... class AnyClassAdmin extends AbstractAdmin { ... use AdminImportTrait;
Both methods add in AdminImportTrait