1. Go to this page and download the library: Download markocupic/export_table 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/ */
markocupic / export_table example snippets
// App/Controller/CustomController.php
declare(strict_types=1);
namespace App\Controller;
use Contao\CoreBundle\Exception\ResponseException;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\FilesModel;
use Markocupic\ExportTable\Config\Config;
use Markocupic\ExportTable\Export\ExportTable;
use Markocupic\ExportTable\Writer\ByteSequence;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/_test_export', name: CustomController::class, defaults: ['_scope' => 'frontend', '_token_check' => false])]
class CustomController extends AbstractController
{
public function __construct(
private ContaoFramework $framework,
private ExportTable $exportTable,
){
}
public function __invoke(): Response
{
$this->framework->initialize();
// First you have to config your data export.
$config = (new Config('tl_member'))
->setExportType('csv')
->setFields(['firstname', 'lastname', 'dateOfBirth'])
->setAddHeadline(true)
->setHeadlineFields(['Vorname', 'Nachname', 'Geburtsdatum'])
->setDelimiter(',')
->setEnclosure('"')
// Select * FROM tl_member WHERE tl_member.city = 'Oberkirch'
->setFilter([["city=?"],["Oberkirch"]])
// Save the file to the Contao filesystem
->setSaveExport(true)
// Define a target path, otherwise the file will be temporarily stored in system/tmp
->setSaveExportDirectory(FilesModel::findByPath('files')->uuid)
// Define a filename, otherwise the file will become the name of the table ->tl_member.csv
->setFilename('export.csv')
// Add BOM (correct display of UTF8 encoded chars in MS-Excel)
->setOutputBom(ByteSequence::BOM['UTF-8'])
// Use the row callback to manipulate records
->setRowCallback(
static function ($arrRow) {
foreach($arrRow as $fieldName => $varValue)
{
$arrRow[$fieldName] = doSomething($varValue);
}
return $arrRow;
}
)
//->convertEncoding(true, 'UTF-8', 'ISO-8859-1');
;
// The export class takes the config object as single parameter.
return $this->exportTable->run($config);
}
}
$config = new Config('tl_member');
$config->setOutputBom(ByteSequence::BOM['UTF-8']);
return $this->exportTable->run($config);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.