/** * CSVを出力する * @access public * @param CSVWriter $writer CSV書き込みクラス * @param PDOStatement|array $sth 出力する値 * @param string $filename 出力するCSV名 * @see Admin_ViewClass::preforward */ function preforward($writer, $sth, $filename) { //CSV出力 header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Type: text/csv;charset=SJIS-win'); $writer->charset = 'SJIS-win'; // 取得結果が0件の場合のヘッダ出力用 // $result = $sth->fetchAll(); // if(count($result)==0){ // $result=(array(0)); // } // foreach ($result as $r) { // $writer->write($r); // } $row = array(); $count = 0; while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $count++; $writer->write($row); } if (0 == $count) { $writer->write($row); } exit; }
/** * Change writer type to convert to another format * * @param string $filetype Set the filetype of the file which will be written (XML/CSV/TSV/HTML/JSON) */ public function convertTo($filetype) { $this->constructWriter($filetype); $this->writer->setData($this->parser->getField()); }