News

Using phpdocx with Zend Framework 2

  • 10 / 18 / 2013

Warning

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

To use phpdocx within the Zend Framework 2, you just need to follow these steps:

1. Extract the content of the phpdocx package to a folder inside the framework path (for example libraries/phpdocx).

2. Go to the module where you want to use phpdocx and open the Module.php file to add the route where to find the main class of phpdocx:

public function getAutoloaderConfig()
 {
  return array(
   'Zend\Loader\ClassMapAutoloader' => array(
    __DIR__ . '/autoload_classmap.php',
    array(
     'CreateDocx' => __DIR__ . '/../../library/phpdocx/classes/CreateDocx.inc',
    ),
   ),
   'Zend\Loader\StandardAutoloader' => array(
    'namespaces' => array(
     __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
    ),
   ),
  );
 }

3. Open the controller and instantiate phpdocx:

public function indexAction()
  {
    $phpdocx = new \CreateDocx();
    $phpdocx->addText('This is a new document created with Zen Framework 2');
    $phpdocx->createDocx('save path');
  }

It is recommended to create a data folder in your module where you can save the new documents created with phpdocx (see this example) .