我看不到如何使用该库并实际上返回一个csv文件,我希望它可以自动打开,如果使用标头,它将返回一个空文件
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
class export {
public function index($data) {
header('Content-type: text/csv');
$serializer = new Serializer([new ObjectNormalizer()], [new
CsvEncoder()]);
// instantiation, when using it inside the Symfony framework
$serializer = $container->get('serializer');
// encoding contents in CSV format
return $serializer->encode($data, 'csv');
}
}