2
私はcsvへのエクスポートにいくつかの問題があります。私のテーブルでは、いくつかのヌル値があり、私はそれらをキャッチする方法を見つけることができません。 エクスポートcsvキャッチnull値symfony 2
public function exportCSVAction()
{
$results = $this->getDoctrine()->getManager()
->getRepository('MyRepoBundle:Cronexecution')->findAll();
$response = new StreamedResponse();
$response->setCallback(
function() use ($results) {
$handle = fopen('php://output', 'r+');
foreach ($results as $row) {
if (!($row->getNbLineIn()) && !($row->getNbLineOut())) {
$delContact = (($row->getNbLineIn()) - ($row->getNbLineOut()));
}
else{
$delContact="Unknown";
}
$data = array(
$row->getClient(),
$row->getDealingName(),
$row->$delContact,
);
fputcsv($handle, $data);
}
fclose($handle);
}
);
$response->headers->set('Content-Type', 'application/force-download');
$response->headers->set('Content-Disposition', 'attachment; filename="export.csv"');
return $response;
}
私は$行削除
- > $ delContactがNULL値ではありませんが、私はそれを聞かせたときに、私は、「このサイトは到達できない」エラーを得たCSVのエクスポート作業原因。私はそれが2つまたは3つの異なる方法でnullだがそれを理解することは不可能であるときにキャッチしようとしました。コードを怒鳴るに従ってあなたの助けのための
おかげ
$行 - > $ delContactがちょうど$ delContactする必要がありますが、あなたは、それがどのようなNULL値私には明確ではないことを言いました話している。 – Cerad
私のgetNbLineOut()とgetNbLineIn()のいくつかはnullなので、エラーをスローし、CSVを作成したくはありません。 – Taloud