public function getResponse()
	{
		if (method_exists($this->controller, 'getResponse'))
		{
			/** @var HttpResponse $response */
			$response = $this->controller->getResponse();
		}
		else
		{
			$response = new HttpResponse;
		}

		$fp = fopen('php://output', 'w');
		ob_start();
		fputcsv($fp, $this->header, $this->delimiter, $this->enclosure);
		foreach ($this->content as $i => $item)
		{
			try
			{
				$fields = $this->callback ? call_user_func($this->callback, $item) : $item;
				if (!is_array($fields))
				{
					throw new \RuntimeException('CsvExport can only accept arrays, '. gettype($fields) .' provided at index '. $i .'. Either use arrays when setting the records or use a callback to convert each record into an array.');
				}
				fputcsv($fp, $fields, $this->delimiter, $this->enclosure);
			}
			catch (\Exception $ex)
			{
				ob_end_clean();
				throw $ex;
			}
		}
		fclose($fp);
		$response->setContent(ob_get_clean());

		$response->getHeaders()->addHeaders(array(
			'Content-Type' => 'text/csv',
			'Content-Disposition' => 'attachment;filename="'. str_replace('"', '\\"', $this->name) .'.csv"',
		));

		return $response;
	}
public function getResponse()
	{
		if (method_exists($this->controller, 'getResponse'))
		{
			/** @var HttpResponse $response */
			$response = $this->controller->getResponse();
		}
		else
		{
			$response = new HttpResponse;
		}

		$fp = fopen('php://output', 'w');
		ob_start();
		fputcsv($fp, $this->header, $this->delimiter, $this->enclosure);
		foreach ($this->content as $i => $item)
		{
			try
			{
				$fields = $this->callback ? call_user_func($this->callback, $item) : $item;
				if (!is_array($fields))
				{
					throw new \RuntimeException('CsvExport can only accept arrays, '. gettype($fields) .' provided at index '. $i .'. Either use arrays when setting the records or use a callback to convert each record into an array.');
				}
				fputcsv($fp, $fields, $this->delimiter, $this->enclosure);
			}
			catch (\Exception $ex)
			{
				ob_end_clean();
				throw $ex;
			}
		}
		fclose($fp);
		$response->setContent(ob_get_clean());

		$response->getHeaders()->addHeaders(array(
			'Content-Type' => 'text/csv',
			'Content-Disposition' => 'attachment;filename="'. str_replace('"', '\\"', $this->name) .'.csv"',
		));

		return $response;
	}
public function getResponse ( ) { if ( method_exists ( $ this -> controller , 'getResponse' ) ) { /** @var HttpResponse $response */ $ response = $ this -> controller -> getResponse ( ) ; } else { $ response = new HttpResponse ; } $ fp = fopen ( 'php://output' , 'w' ) ; ob_start ( ) ; fputcsv ( $ fp , $ this -> header , $ this -> delimiter , $ this -> enclosure ) ; foreach ( $ this -> content as $ i => $ item ) { try { $ fields = $ this -> callback ? call_user_func ( $ this -> callback , $ item ) : $ item ; if ( ! is_array ( $ fields ) ) { throw new \ RuntimeException ( 'CsvExport can only accept arrays, ' . gettype ( $ fields ) . ' provided at index ' . $ i . '. Either use arrays when setting the records or use a callback to convert each record into an array.' ) ; } fputcsv ( $ fp , $ fields , $ this -> delimiter , $ this -> enclosure ) ; } catch ( \ Exception $ ex ) { ob_end_clean ( ) ; throw $ ex ; } } fclose ( $ fp ) ; $ response -> setContent ( ob_get_clean ( ) ) ; $ response -> getHeaders ( ) -> addHeaders ( array ( 'Content-Type' => 'text/csv' , 'Content-Disposition' => 'attachment;filename="' . str_replace ( '"' , '\\"' , $ this -> name ) . '.csv"' , ) ) ; return $ response ; }
Prepare the response with the CSV export and return it

@return HttpResponse
@throws \Exception if any exceptions are thrown within the content callback
Prepare the response with the CSV export and return it