Giter VIP home page Giter VIP logo

sonataimportbundle's Introduction

Установка

composer require doctrs/sonata-import-bundle

Добавляем бандл в AppKernel.php

new Doctrs\SonataImportBundle\DoctrsSonataImportBundle()

Данный бандл так же подтягивает white-october/pagerfanta-bundle. Если у вас его нет, то его тожде необхоидмо добавить в AppKernel.php

new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),

Добавляем mapping в файл config.yml

doctrine:
    # ...
    orm:
        # ...
        entity_managers:
            default:
                mappings:
                    DoctrsSonataImportBundle: ~

и сами настройки бандла

doctrs_sonata_import:
    mappings:
        - { name: center_point, class: doctrs.form_format.point}
        - { name: city_autocomplete, class: doctrs.form_format.city_pa}
    upload_dir: %kernel.root_dir%/../web/uploads    
    class_loader: Doctrs\SonataImportBundle\Loaders\CsvFileLoader
    encode:
        default: utf8
        list:
            - cp1251
            - utf8
            - koir8

Создаем базу

php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate

Или, если нет миграций

php app/console doctrine:schema:update --force

Установка бандла завершена

Изменение сущностей sonataAdminBundle

Добавляем или изменяем метод configureRoutes в классах, на основе которых создается sonata admin

    protected function configureRoutes(RouteCollection $collection)
    {
        $collection->add('import', 'import', [
            '_controller' => 'DoctrsSonataImportBundle:Default:index'
        ]);
        $collection->add('upload', '{id}/upload', [
            '_controller' => 'DoctrsSonataImportBundle:Default:upload'
        ]);
    }

В каждый класс, который предстоит импортировать, нужно будет изменить метод соответствующим образом.

По данным ссылкам можно переходить либо напрямую в URL, либо добавить ссылки на главную

Для добавления ссылки на главной, можно изменить/добавить метод getDashboardActions следующим образом

    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;
    }

Если у вас эти методы не определены в админ классах, то можно просто использовать трейт

use Doctrs\SonataImportBundle\Admin\AdminImportTrait;
...
class EntityAdmin extends AbstractAdmin {
...
use AdminImportTrait;

Оба метода описанные выше добавленны в AdminImportTrait

sonataimportbundle's People

Contributors

doctrs avatar

Watchers

Yauheni avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.