Hi Tweakers,
Ik ben op dit moment Symfony/Pimcore aan het leren
Nu wil ik mijn CSV-file importeren, via de commando. Ik heb al er van alles geprobeerd. Het is niet zo makkelijk als met Laravel en Magento.
Ik wil dit binnen pimcore doen.
Dit is de code die ik al geprobeerd heb, maar helaas doet het niet… maar tegelijktijdig zie ik dat de code kan de velden van de tabellen uitlezen.
Ik ben op dit moment Symfony/Pimcore aan het leren
Nu wil ik mijn CSV-file importeren, via de commando. Ik heb al er van alles geprobeerd. Het is niet zo makkelijk als met Laravel en Magento.
Ik wil dit binnen pimcore doen.
Dit is de code die ik al geprobeerd heb, maar helaas doet het niet… maar tegelijktijdig zie ik dat de code kan de velden van de tabellen uitlezen.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| protected function configure() { $this ->setName('branch:import') ->setDescription('Branch cagai'); } /** * @param InputInterface $input * @param OutputInterface $output * * @return void * @throws UnableToProcessCsv */ protected function execute(InputInterface $input, OutputInterface $output): void { $io = new SymfonyStyle($input, $output); $io->title('Attempting import of Feed...'); $reader = Reader::createFromPath('%kernel.root_dir%/../public/branch.csv'); // https://github.com/thephpleague/csv/issues/208 $results = $reader->fetchColumn(); foreach ($results as $row){ // create new branch $branch = (new Branch()) ->setMcmcu('mcmcu') ->setMcco('mcco'); $this->em->persist($branch); } $this->em->flush(); $io->success('command exited cleanly!'); } |