Backup\Model\Content::export PHP Method

export() public method

Export function
public export ( array $what ) : string
$what array What will be exported
return string
    public function export(array $what)
    {
        if (empty($what)) {
            return '';
        }
        $xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
        $xml .= '<gotcms>';
        foreach ($what as $type) {
            $xml .= $this->createXml($type);
        }
        $xml .= '</gotcms>';
        return $xml;
    }

Usage Example

Esempio n. 1
0
 /**
  * Download files as gzip
  *
  * @return \Zend\Stdlib\ResponseInterface
  */
 public function downloadContentAction()
 {
     $what = $this->params()->fromPost('what');
     if (empty($what) or !is_array($what)) {
         return $this->redirect()->toRoute('module/backup');
     }
     $model = new Model\Content($this->getServiceLocator());
     $content = $model->export($what);
     $filename = 'content-backup-' . date('Y-m-d-H-i-s') . '.xml';
     $headers = new Headers();
     $headers->addHeaderLine('Pragma', 'public')->addHeaderLine('Cache-control', 'must-revalidate, post-check=0, pre-check=0')->addHeaderLine('Cache-control', 'private')->addHeaderLine('Expires', -1)->addHeaderLine('Content-Type', 'application/download')->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Length', strlen($content))->addHeaderLine('Content-Disposition', 'attachment; filename=' . $filename);
     $response = $this->getResponse();
     $response->setHeaders($headers);
     $response->setContent($content);
     return $response;
 }