https://csv.thephpleague.com/9.0/
Мне удалось сделать первые шаги: создать команду, прочитать CSV-файл и выполнить над ним «эхо».
Код: Выделить всё
protected function execute(
InputInterface $input,
OutputInterface $output
): int {
$io = new SymfonyStyle($input, $output);
$io->title('Import CSV ...');
$csv = Reader::from('src/Data/testuser.csv', 'r');
$csv->setHeaderOffset(0);
$csv->setEscape('');
$records = $csv->getRecords();
echo $csv->toString();
$io->success('Great CSV in DB !');
return Command::SUCCESS;
}
Код: Выделить всё
foreach ($records as $record){
$user = (new User())
->setName($record['name'])
->setSurname($record['surname'])
->setEmail($record['email'])
->setRoles($record['roles'])
->setPlainPassword($record['plainPassword'])
;
$this->em->persist($user);
}
$this->em->flush();
Подробнее здесь: https://stackoverflow.com/questions/798 ... v-properly
Мобильная версия