我正在通过 CSV 格式进行数据导出。
问题:当数据包含空格时,它会跳转到csv文件中的列
在customer_id = 8
的图像检查中 地址1中的正确值是" starline appartment"但是" starline"留在地址1和"公寓"进入地址2。
这是控制器代码
$em = $this->getDoctrine()->getManager('db1');
$connection = $em->getConnection();
$query = "SELECT *
FROM customers
ORDER BY customer_id ASC
LIMIT 10";
$statement = $connection->prepare($query);
$statement->execute();
$rows = $statement->fetchAll();
$columns = $em->getClassMetadata('AdminSporteventsBundle:Customers')->getFieldNames();
foreach ($columns as $value) {
$finalcolumns[] = strtolower(preg_replace('/\B([A-Z])/', '_$1', $value));
}
//echo "<pre>";print_r($rows);echo "</pre>";die;
$response = $this->render('AdminSporteventsBundle:Export:export.csv.twig', array('data' => $rows));
$filename = "export_".date("Y_m_d_His").".csv";
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
return $response;
这是我的查看文件代码
cusromer_id, email_id, facebook_id, password, forname, surname, house_no, address1, address2, town, country, postcode, mobile, telepnone, created_date, updated_date
{% for customer in data %}
{{ customer.customer_id }}, {{ customer.email_id }}, {{ customer.facebook_id }}, {{ customer.password }}, {{ customer.forname }}, {{ customer.surname }}, {{ customer.house_no }}, {{ customer.address1 }}, {{ customer.address2 }}, {{ customer.town }}, {{ customer.country }}, {{ customer.postcode }}, {{ customer.mobile }}, {{ customer.telepnone }}, {{ customer.created_date }}, {{ customer.updated_date }}
{% endfor %}
那么我该怎么做才能解决这个问题?