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

Export Raw Files?

Discussion in 'XenForo Development Discussions' started by Jaxel, Aug 21, 2015.

  1. Jaxel

    Jaxel Well-Known Member

    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: Aug 21, 2015
  2. cclaerhout

    cclaerhout Well-Known Member

    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()" ?
     
  3. Jaxel

    Jaxel Well-Known Member

    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?
     
  4. cclaerhout

    cclaerhout Well-Known Member

    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'];
       }
    }
     
  5. Jaxel

    Jaxel Well-Known Member

    I wish this was Stackoverflow, so I could accept your answer.
     
    cclaerhout likes this.

Share This Page