Thanks again for teaching me the basics!If anybody else with my lack of knowledge in namespaces; this is what I did:Instead of using the following:
use PhpOffice\PhpWord\Style\Paper;
use PhpOffice\PhpWord\Style\Language;
use PhpOffice\PhpWord\Writer\Word2007\Style\Font;
I have to write the full qualified name when using the functions in PhpOffice like this:
$phpWord = new \PhpOffice\PhpWord\PhpWord()
$paper = new \PhpOffice\PhpWord\Style\Paper();
Also the constants f.ex language needs the full qualified name:
\PhpOffice\PhpWord\Style\Language::SV_SE
So moving from separate php-file into routes when creating phpword documents I did this:Server Events->Global->All pages → Route_Actions
$app->get('/createdoc/{id}', function ($request, $response, array $args) {
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$paper = new \PhpOffice\PhpWord\Style\Paper();
$phpWord->getSettings()->setThemeFontLang(new \PhpOffice\PhpWord\Style\Language(\PhpOffice\PhpWord\Style\Language::SV_SE));
// ...
// Do all stuff about the same and end with this:
$response->getBody()->write(''); // Write an empty response body so you don't interfere with the creation of the Word document.
return $response; // Return the response
});
At least this worked for me, perhaps it can be made more neat but it works!