我没有意识到 LiveDocx 只存储要引用的文件的名称。我使用以下方法发现了这一点:
$mailMerge->listImages();
格式是这样回来的:
array
0 => array
'filename' => string 'directory_logo.png' (length=18)
'fileSize' => int 12829
'createTime' => int 1352835686
'modifyTime' => int 1352835686
所以模板文件可以使用这种格式:
«image:photo»
又名
{ MERGEFIELD image:photo \* MERGEFORMAT }
但我的 php 需要看起来像这样:
$mailMerge->uploadImage($this->logo_path);
$mailMerge->assign('image:photo', $this->logo_file);
我的完整工作代码如下所示:
$mailMerge = new Zend_Service_LiveDocx_MailMerge();
$mailMerge->setUsername($username)
->setPassword($password);
$mailMerge->setLocalTemplate($template_path . '/service_template.docx');
$mailMerge->uploadImage($this->logo_path);
$mailMerge->assign('image:photo', 'directory_logo.png');
$mailMerge->createDocument();
$document = $mailMerge->retrieveDocument('docx');
file_put_contents($this->config->livedocx->document . '/' . $this->prefs['serverid'] . '/service_directory.docx', $document);
$mailMerge->deleteImage('directory_logo.png');