curtisnt
curtisnt

Reputation: 13

PHPWord - Class 'Footer' not found

I need to add a footer to the first page of my document:

    require_once 'vendor\autoload.php';
    $phpWord = new \PhpOffice\PhpWord\PhpWord();
    $section = $phpWord->addSection(array(
        'orientation' => 'portrait')
     );
    $footer = $section->addFooter(Footer::FIRST); <- Line 49

but I get an error:

Uncaught Error: Class 'Footer' not found in C:\xxxxxxxxxx:49

I've even tried requiring Footer.php in the package. Word document generation works fine without the Footer::FIRST parameter though I get the footer on every page. I also just upgraded to version 0.17 Any ideas why the error is occurring?

Upvotes: 0

Views: 231

Answers (1)

Ermenegildo
Ermenegildo

Reputation: 1308

Without the full namespace, PHP won't be able to find the right Footer class. To solve this, simply declare the full namespace of footer class

$footer = $section->addFooter(\PhpOffice\PhpWord\Element\Footer::FIRST);

Upvotes: 3

Related Questions