public function export($id = null, $type = 'docx') {
		$type = mb_strtolower($type);
		if (!empty($type) && !$this->_controller->RequestHandler->prefers($type)) {
			throw new BadRequestException(__d('view_extension', 'Invalid request'));
		}

		if (!method_exists($this->_model, 'generateExportFile') || !method_exists($this->_model, 'getExportFilename')) {
			throw new InternalErrorException(__d('view_extension', 'Export method not found'));
		}

		$tempFile = $this->_model->generateExportFile($id);
		if (empty($tempFile)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid generated file'));
		}

		$exportFile = pathinfo($tempFile, PATHINFO_FILENAME);

		return $this->download($id, $exportFile);
	}
public function export($id = null, $type = 'docx') {
		$type = mb_strtolower($type);
		if (!empty($type) && !$this->_controller->RequestHandler->prefers($type)) {
			throw new BadRequestException(__d('view_extension', 'Invalid request'));
		}

		if (!method_exists($this->_model, 'generateExportFile') || !method_exists($this->_model, 'getExportFilename')) {
			throw new InternalErrorException(__d('view_extension', 'Export method not found'));
		}

		$tempFile = $this->_model->generateExportFile($id);
		if (empty($tempFile)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid generated file'));
		}

		$exportFile = pathinfo($tempFile, PATHINFO_FILENAME);

		return $this->download($id, $exportFile);
	}
public function export ( $ id = null , $ type = 'docx' ) { $ type = mb_strtolower ( $ type ) ; if ( ! empty ( $ type ) && ! $ this -> _controller -> RequestHandler -> prefers ( $ type ) ) { throw new BadRequestException ( __d ( 'view_extension' , 'Invalid request' ) ) ; } if ( ! method_exists ( $ this -> _model , 'generateExportFile' ) || ! method_exists ( $ this -> _model , 'getExportFilename' ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Export method not found' ) ) ; } $ tempFile = $ this -> _model -> generateExportFile ( $ id ) ; if ( empty ( $ tempFile ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid generated file' ) ) ; } $ exportFile = pathinfo ( $ tempFile , PATHINFO_FILENAME ) ; return $ this -> download ( $ id , $ exportFile ) ; }
Export file from server

@param int|string $id ID for exported data.
@param string $type Extension of exported file.
@throws BadRequestException if not empty $type and extension of
requested file is not equal $type.
@throws InternalErrorException if method Model::generateExportFile() is
not exists.
@throws InternalErrorException if empty result of call method Model::generateExportFile().
@return object Return response object of exported file.
Export file from server