title: PHPWord_Template save to client
body: <p>I have download the package PHPWord_0.6.2_Beta.zip from <a href="http://phpword.codeplex.com/releases/view/49543" rel="nofollow">this site</a><br><br>There are 2 directory : Examples and PHPWord, and 1 file : PHPWord.php<br>I put PHPWord directory and PHPWord.php in application/third_party and create new library named 'Word.php' in application/libraries as explained in <a href="http://www.ahowto.net/php/creating-ms-word-document-using-codeigniter-and-phpword" rel="nofollow">this article</a><br><br>Here is the new library code Word.php<br></p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  require_once APPPATH."/third_party/PHPWord.php"; 
  
  class Word extends PHPWord { 
      public function __construct() { 
          parent::__construct(); 
      } 
  }
  ?&gt;
  </code></pre>
  
  <p><br>Now we can easily use PHPWord as CI library<br><br>I have tried Text Example from directory Example in downloaded package, here is the original code</p>
  
  <pre><code>&lt;?php
  require_once '../PHPWord.php';
  
  // New Word Document
  $PHPWord = new PHPWord();
  
  // New portrait section
  $section = $PHPWord-&gt;createSection();
  
  // Add text elements
  $section-&gt;addText('Hello World!');
  $section-&gt;addTextBreak(2);
  
  $section-&gt;addText('I am inline styled.', array('name'=&gt;'Verdana', 'color'=&gt;'006699'));
  $section-&gt;addTextBreak(2);
  
  $PHPWord-&gt;addFontStyle('rStyle', array('bold'=&gt;true, 'italic'=&gt;true, 'size'=&gt;16));
  $PHPWord-&gt;addParagraphStyle('pStyle', array('align'=&gt;'center', 'spaceAfter'=&gt;100));
  $section-&gt;addText('I am styled by two style definitions.', 'rStyle', 'pStyle');
  $section-&gt;addText('I have only a paragraph style definition.', null, 'pStyle');
  
  
  
  // Save File
  $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
  $objWriter-&gt;save('Text.docx');
  ?&gt;
  </code></pre>
  
  <p><br>And I tried implement it in my CI controller, here is the code PHPWord_Text.php</p>
  
  <pre><code>&lt;?php if (!defined('BASEPATH')) exit ('No direct script access allowed');
  class PHPWord_Text extends CI_Controller {
      function __construct() {
          parent::__construct();
          $this-&gt;load-&gt;library('word');
      }
      function index() {
          $PHPWord = $this-&gt;word; // New Word Document
          $section = $PHPWord-&gt;createSection(); // New portrait section
          // Add text elements
          $section-&gt;addText('Hello World!');
          $section-&gt;addTextBreak(2);
          $section-&gt;addText('I am inline styled.', array('name'=&gt;'Verdana', 'color'=&gt;'006699'));
          $section-&gt;addTextBreak(2);
          $PHPWord-&gt;addFontStyle('rStyle', array('bold'=&gt;true, 'italic'=&gt;true, 'size'=&gt;16));
          $PHPWord-&gt;addParagraphStyle('pStyle', array('align'=&gt;'center', 'spaceAfter'=&gt;100));
          $section-&gt;addText('I am styled by two style definitions.', 'rStyle', 'pStyle');
          $section-&gt;addText('I have only a paragraph style definition.', null, 'pStyle');
          // Save File / Download (Download dialog, prompt user to save or simply open it)
          $filename='just_some_random_name.docx'; //save our document as this file name
          header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); //mime type
          header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
          header('Cache-Control: max-age=0'); //no cache
          $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
          $objWriter-&gt;save('php://output');
      }
  }
  ?&gt;
  </code></pre>
  
  <p><br>Access it in</p>
  
  <pre><code>http://localhost/codeigniter/index.php/PHPWord_Text
  </code></pre>
  
  <p><br>Foilaa!!! my code works! But... I'm a bit confused when i tried to translate Template Example in directory Examples from downloaded package into a new CI controller, here is the original code of Template.php</p>
  
  <pre><code>&lt;?php
  require_once '../PHPWord.php';
  
  $PHPWord = new PHPWord();
  
  $document = $PHPWord-&gt;loadTemplate('Template.docx');
  
  $document-&gt;setValue('Value1', 'Sun');
  $document-&gt;setValue('Value2', 'Mercury');
  $document-&gt;setValue('Value3', 'Venus');
  $document-&gt;setValue('Value4', 'Earth');
  $document-&gt;setValue('Value5', 'Mars');
  $document-&gt;setValue('Value6', 'Jupiter');
  $document-&gt;setValue('Value7', 'Saturn');
  $document-&gt;setValue('Value8', 'Uranus');
  $document-&gt;setValue('Value9', 'Neptun');
  $document-&gt;setValue('Value10', 'Pluto');
  
  $document-&gt;setValue('weekday', date('l'));
  $document-&gt;setValue('time', date('H:i'));
  
  $document-&gt;save('Solarsystem.docx');
  ?&gt;
  </code></pre>
  
  <p><br>Can anyone please help me with this problem? please.. T_T<br><strong>NOTE</strong> : i dont want it to be saved in server, i want it to show download dialog prompt user wether to save it or open it, works like some code down here</p>
  
  <pre><code>// Save File / Download (Download dialog, prompt user to save or simply open it)
  $filename='just_some_random_name.docx'; //save our document as this file name
  header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); //mime type
  header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
  header('Cache-Control: max-age=0'); //no cache
  $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
  $objWriter-&gt;save('php://output');
  </code></pre>