webworksnbg/csv-bundle

此包已被弃用且不再维护。未建议替换包。

webworksCSVBundle

安装: 82

依赖: 0

建议者: 0

安全: 0

星标: 4

关注者: 2

分支: 0

类型:symfony-bundle

1.0.6 2019-05-07 07:57 UTC

This package is not auto-updated.

Last update: 2023-02-12 01:39:49 UTC


README

webworksCSVBundle帮助您在Symfony应用程序中处理csv数据和文件。它为doctrine提供了基于YAML的简单映射。

需求

  • PHP 7.x
  • Symfony 3.x
  • 参见composer.json文件

安装

步骤1:使用composer下载webworksCSVBundle

使用composer要求包

composer require webworksnbg/csv-bundle "~0.1"

步骤2:启用包

在内核中启用包

// app/AppKernel.php
 
public function registerBundles()
{
    $bundles = array(
        // ...
        new webworks\CSVBundle\webworksCSVBundle(),
        // ...
    );
}

步骤3:创建映射YAML文件

创建以下内容的YAML文件(例如)

# app/config/csv/mapping.yml
 
import:
# not supported in the current version
 
export:
    clients: # mapping name 
        class: acme\AppBundle\Entity\Kunde
        mapping:
            name:         firstname, lastname
            street:       street
            city:         zip, city
            email:        email
            company:      company_name

注意:目前,只能进行一次数据导出。导入功能将很快推出

步骤4:使用映射服务将数据从数据库写入csv

您可以从容器中调用服务

// where ever you have an container
 
$csvPath = $this->getContainer()->get('webworks.csv.mapping')
    ->setMappingName('clients') // mapping name
    ->setMode('export')
    ->process()
    ->getPath(); // Temporary file path!

步骤5:享受 :)

现在,您可以通过doctrine轻松将数据从数据库写入csv。

致谢

此包由webworks nürnberg和社区创建。

示例

解析CSV文件

use webworks\CSVBundle\Lib\ParseCSV;
 
$parser = new ParseCSV('example.csv', ';', '"');
$data = $parser->parse();