Forum


Replies: 5   Views: 3397
Addcrossreference on wordfragment
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by AndrewCooper  · 15-06-2016 - 12:39

I'm doing the following...

$xref = new WordFragment($docx);
$xref->addCrossReference("blah", array("type" => "bookmark", "referenceName" => "blah"));

And get an error stating that the WordFragment class doesn't have an addCrossReference method.  Is this a licencing issue or version issue?  Since every other Word Content method seems to work on a Word Fragment, I would expect this to do the same. If this isn't the case, could I ask why not?

Andrew

Posted by admin  · 15-06-2016 - 14:28

Hello,

We have tested it and it's working perfectly. Which version of phpdocx are you using?

Regards.

Posted by AndrewCooper  · 17-06-2016 - 06:45

That's good news.  I'm glad I'm doing something wrong. I figured it made sense to be able to add cross references on fragments.

I'm using 5.5 trial at the moment.  I believe we are about to purchase the Corporate version of 6.0. Waiting on the final approval for that.

Here's my whole php file.

<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once 'phpdocx/classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->addText("Blargity blarg-blarg blarg.");

$xref = new WordFragment($docx);
$xref->addCrossReference("blah", array("type" => "bookmark", "referenceName" => "blah"));
$docx->addText($xref);

$docx->createDocx('document');
echo "<a href='document.docx'>Document</a>";

And here is the error message I'm getting on the server.

[Fri Jun 17 08:42:13.892890 2016] [:error] [pid 2082] [client 192.168.56.100:61678] PHP Fatal error:  Call to undefined method WordFragment::addCrossReference() in /webdevroot/Test/DocGen/sandbox.php on line 11

Am I missing something here?

Thanks,

Andrew

Posted by admin  · 17-06-2016 - 07:15

Hello,

The addCrossReference method is a new feature from phpdocx 6, it's not available in phpdocx 5.5.

Regards.

Posted by AndrewCooper  · 17-06-2016 - 07:32

Well, that explains a lot. :)

Thanks!

Posted by AndrewCooper  · 17-06-2016 - 08:57

Just for your general information.

In the addBookmark function (line 1084 of CreateDocx.inc) the code checks whether the type and name are empty. Problem is that if the name value is "0" (a string zero) the check incorrectly returns a true on the empty(name) check.  

This is an edge case for sure but it did happen for me.

Andrew