PHP code example of kunicmarko / sonata-importer-bundle
1. Go to this page and download the library: Download kunicmarko/sonata-importer-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kunicmarko / sonata-importer-bundle example snippets
return [
//...
KunicMarko\SonataImporterBundle\SonataImporterBundle::class => ['all' => true],
];
class CategoryCSVImportConfiguration implements SonataImportConfiguration
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
public static function adminClass(): string
{
return CategoryAdmin::class;
}
public static function format(): string
{
return 'csv';
}
public function map(array $item, array $additionalData)
{
$category = new Category();
$category->setName($item[0]);
$this->entityManager->persist($category);
}
public function save(array $items, array $additionalData): void
{
$this->entityManager->flush();
}
}