PHP code example of i-lateral / silverstripe-slightly-better-bulkloader
1. Go to this page and download the library: Download i-lateral/silverstripe-slightly-better-bulkloader 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/ */
i-lateral / silverstripe-slightly-better-bulkloader example snippets
namespace App\Admin;
use SilverStripe\Admin\ModelAdmin;
use ilateral\SilverStripe\SlightlyBetterBulkLoader\CsvBulkLoader;
class MyModelAdmin extends ModelAdmin
{
private static $managed_models = [
MyDataObject::class
];
private static $model_importers = [
MyDataObject::class => CsvBulkLoader::class
];
}
use SilverStripe\Forms\Form;
use ilateral\SilverStripe\SlightlyBetterBulkLoader\CsvBulkLoader;
class MyImportForm extends Form
{
public function import($data, $form)
{
$loader = CsvBulkLoader::create();
$results = $loader->load($_FILES['_CsvFile']['tmp_name']);
$form->sessionMessage(
$results->getMessagesString("</br>"),
$results->getMessageType(),
ValidationResult::CAST_HTML
);
return $this->redirectBack();
}
}