Cookbook

Integrate phpdocx with CodeIgniter

Using phpdocx with CodeIgniter is as simple as copying the phpdocx content package to the application/libraries/phpdocx directory and load the CreateDocx class.

To have the phpdocx API methods available, just load the library in the controller:

x
 
1
public function index()
2
{
3
    $this->load->library('phpdocx/classes/CreateDocx', '', 'phpdocx');
4
5
    $this->phpdocx->addText('This is a test');
6
    $this->phpdocx->embedHTML('<p style="font-size: 30px;">New paragraph</p>');
7
    $this->phpdocx->createDocx(APPPATH . '/documents/output.docx');
8
}
9

In order to save the document, the documents folder in the APPATH path must have read/write permissions.

Warning

To run phpdocx with CodeIgniter 4 it is mandatory to use the package that supports namespaces. This package is available for Advanced and Premium licenses.

­
­