Hello,
In the current stable release of phpdocx, page-of type page numbering must be added as block content, as it doesn't support being added as inline content (numerical or alphabetical types support it).
Instead of adding it as a inline content in the text array please add a new block content in the same WordFragment:
$footerWordFragment = new WordFragment($docx, 'defaultFooter');
$ftr = array();
$ftr[] = array('text' => 'Generic footer text ');
$footerWordFragment->addText($ftr);
$footerWordFragment->addPageNumber('page-of');
$docx->addFooter(array('default' => $footerWordFragment));
Or in a table using WordFragments:
$numberingFragment = new WordFragment($docx, 'defaultFooter');
$numberingFragment->addPageNumber('page-of');
$footerWordFragment = new WordFragment($docx, 'defaultFooter');
$valuesTable = array(
array(
'Generic footer text ',
$numberingFragment,
),
);
$footerWordFragment->addTable($valuesTable);
$docx->addFooter(array('default' => $footerWordFragment));
We have sent this use case to the dev team and they have added a patch to the testing branch to include support to page-of type as inline content (it will be included in the next stable release). If you need this patch, please send an email to contact[at]phpdocx.com and we'll send you the updated class (please also send if you are using the classic or the namespaces package).
Regards.