News

Using phpdocx with Yii

  • Sep 26, 2013

Warning

This post is outdated. For up date information about using phpdocx with Yii please refer to the Integrate phpdocx with Yii 2.

To use phpdocx within the Yii framework, you just need to follow these steps in your controller:

 

// unregister Yii autoloader
spl_autoload_unregister(array('YiiBase', 'autoload'));
// import the library
Yii::import('application.vendor.phpdocx.*');
// include the required libraries
require_once 'lib/log4php/Logger.php';
require_once 'classes/CreateDocx.inc';

// create the new document
$docx = new CreateDocx();
$text = 'New text.';

$paramsText = array(
'b' => 'on',
'font' => 'Arial'
);

$docx->addText($text, $paramsText);
$docx->createDocx('example_text');

// register Yii autoloader again
spl_autoload_register(array('YiiBase', 'autoload'));

To set the path where to save the documents we recommend you
use a config param in protected/config/main.php:

 

'params'=>array(
'uploadPath'=>dirname(__FILE__).'/../../images/upload',
'uploadUrl'=>'/images/upload',
),

// add this parameter to set the path where to save the document:

$docx->createDocx(Yii::app()->params['uploadPath']. '/' .'example_text');