symfony 无法导出带有日期时间数据的 csv

symfony can't export csv with date time data

有此行时无法将文件导出为 CSV $row->getcreateAt()

$response = new StreamedResponse();
        $response->setCallback(
            function () use ($results) {
                $handle = fopen('php://output', 'w+');
                foreach ($results as $row) {
                    //array list fields you need to export
                    $data = [
                        $row->getId(),
                        $row->getcreateAt(),
                        $row->getPtfName(),
                    ];
                    fputcsv($handle, $data);
                }
                fclose($handle);
            }
        );

您需要将 DateTime 格式化为字符串:

$data = [
  $row->getId(),
  $row->getcreateAt()->format('Y-m-d H:i:s'),
  $row->getPtfName(),
];