Cookbook

Integrate phpdocx with Symfony

Warning

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

The installation of phpdocx in a project that works with Composer can be manual or using a private repository with GitHub, Bitbucket or any other distributed version control system.

In order to use a private repository with GitHub or Bitbucket, you have to generate and use an SSH key:

To perform a manual integration just follow these easy steps:

  • 1- Copy the content of the phpdocx package in the folder vendor/phpdocx.
  • 2- Open the file composer.json. Add the following classmap in the autoload section:
    "vendor/phpdocx/Classes/Phpdocx"
In a Symfony 2 and Symfony 3 clean installation, the section should look like this:

In a Symfony 4, Symfony 5 and Symfony 6 clean installation, the section should look like this:

  • 3- Update the autoloader of Composer:

Now, with these three easy steps completed, you can work with phpdocx.

As an example, let's create a document in a controller and then save it in a public folder with the name output.docx: