I try to to implement Connector Service svconnector (1) in an extension in TYPO3 12 to show the content of a CSV with FLUID.
Following the manual (2) I created the following class:
// *Classes/Services/Publications.php*
namespace Vendor\Publications\Service;
abstract class Publications
extends \Cobweb\Svconnector\Service\ConnectorBase
{}
I also added the following to register the service:
# *Configuration/Services.yaml*
Cobweb\SvconnectorCsv\Service\ConnectorCsv:
public: true
arguments:
- !tagged_iterator connector.service
Now I would like to connect to a CSV-file using the following code in my Class (see here (3) in the manual):
$registry = GeneralUtility::makeInstance(
\Cobweb\Svconnector\Registry\ConnectorRegistry::class
);
$connector = $registry->getServiceForType('csv');
I do not understand where to place this code to register the class and implement the service.
In TYPO3 11 the connection code was implemented in the following file but it does not work in TYPO3 12.
Classes/Controller/PublicationsController.php
I really appreciate your help.
First of all you can delete the Class:
Classes/Services/Publications.php
And remove the configuration you made in:
Configuration/Services.yaml
This is only needed if you want to implement your own custom connector service. To access a csv file there is already an extension that implements a csv connector service.
To use the csv connector service you need to install this two extensions:
Now you can implement the needed code in your controller:
Classes/Controller/PublicationsController.php
As described in the manual here:
https://docs.typo3.org/p/cobweb/svconnector_csv/4.1/en-us/Developer/Index.html
Assuming you have a showAction for your frontend plugin you need to implement it like that:
public function showAction()
{
$registry = GeneralUtility::makeInstance(
\Cobweb\Svconnector\Registry\ConnectorRegistry::class
);
$connector = $registry->getServiceForType('csv');
$parameters = [
'filename' => 'path/to/your/file',
'delimiter' => "\t",
'text_qualifier' => '',
'encoding' => 'utf-8',
'skip_rows' => 1,
];
$csvData = $connector->fetchArray($parameters);
$this->view->assign('csvData', $csvData);
return $this->htmlResponse();
}