• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Export Raw Files?

Jaxel

Well-known member
#1
How do I get XenForo to export files?

For instance, I have event details, and I would like to export those event details in a CSV file.

I have tried the following with no luck:

Controller:
Code:
$this->_routeMatch->setResponseType('raw');
View:
Code:
public function renderRaw()
{
    $this->_params['ical'] = "BEGIN:VCALENDAR
        VERSION:2.0
        PRODID:-//project/author//NONSGML v1.0//EN
        CALSCALE:GREGORIAN
        BEGIN:VEVENT
        DTSTAMP:" . date('Ymd\Tgis\Z', XenForo_Application::$time) . "
        DTSTART:" . date('Ymd\Tgis\Z', $this->_params['occur']['occur_start']) . "
        DTEND:" . date('Ymd\Tgis\Z', $this->_params['occur']['occur_end']) . "
        UID:" . $this->_params['occur']['occur_id'] . "
        SUMMARY:" . htmlspecialchars($this->_params['occur']['event_title']) . "
        END:VEVENT
        END:VCALENDAR";

    $this->_response->setHeader('Content-type: text/calendar; charset=utf-8', true);
    $this->setDownloadFileName($this->_params['occur']['occur_id'] . '.ics');
  
    return $this->_params['ical']->saveRaw();
}
 
Last edited:

cclaerhout

Well-known member
#2
Check your setHeader values. The function setHeader (Zend_Controller_Response_Abstract) supports 3 arguments.
Source:
PHP:
  /**
  * Set a header
  *
  * If $replace is true, replaces any headers already defined with that
  * $name.
  *
  * @param string $name
  * @param string $value
  * @param boolean $replace
  * @return Zend_Controller_Response_Abstract
  */
  public function setHeader($name, $value, $replace = false)
  {
Ie:
PHP:
$this->_response->setHeader('Content-type', 'application/txt', true);
I'm curious, what is the purpose of the "saveRaw()" ?
 

Jaxel

Well-known member
#3
I'm curious, what is the purpose of the "saveRaw()" ?
Honestly? I have no idea.

When I do an xml content type, I need to use saveXml() to tell the system what information to output into the file. If I dont, then the file is completely blank.

However, using saveRaw() gives me the following error:
Code:
Fatal error: Call to a member function saveRaw() on a non-object
So how do I tell the system what data to put in the file?
 

cclaerhout

Well-known member
#4
Honestly? I have no idea.

When I do an xml content type, I need to use saveXml() to tell the system what information to output into the file. If I dont, then the file is completely blank.

However, using saveRaw() gives me the following error:
Code:
Fatal error: Call to a member function saveRaw() on a non-object
So how do I tell the system what data to put in the file?
Since it's raw, just export the data like they come.

Here's what I've done quite ago (and it works):
PHP:
<?php

class Sedo_PoManager_ViewAdmin_Language_ExportPo extends XenForo_ViewAdmin_Base
{
   public function renderRaw()
   {
     $poFile = $this->_params['po'];
     $this->_response->setHeader('Content-type', 'application/txt', true); //application/octet-stream
     $this->setDownloadFileName($this->_params['filename'] . '.po', true);        
     return $this->_params['po'];
   }
}