/** * Export action */ public function exportAction() { $request = $this->getRequest(); $form = $this->getServiceLocator()->get('Form')->get('Grid\\Core\\ListExport'); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); $type = $data['type']; $options = array_merge((array) (isset($data[$type]) ? $data[$type] : array()), array('fieldNames' => $this->getExportFieldNames())); $iterator = $this->getPaginator()->getAdapter()->getItems(0, null); $table = new Table($iterator, $this->getExportFieldTypes()); $response = FileData::fromData($table->export($type, $options), $this->getExportFileName($type)); $this->getEvent()->setResponse($response); return $response; } } $view = new ViewModel(array('form' => $form->setAttribute('action', $request->getRequestUri()))); return $view->setTemplate('rowSet/export')->setTerminal(true); }
/** * Test unknown export type * * @expectedException InvalidArgumentException */ public function testUnknownExport() { $table = new Table($this->data, $this->fields); $table->export('unknown_type'); }